Derived a derived class with the base class of the template and the template argument

I have a quick question in the hope that someone knows if what I am trying to do is possible.

Suppose I have a base template class such as

template <class T> CBase { public: CBase() {} void print() { std::cout << n std::endl; } private: T m_var; }; 

And I want the derived class to be derived from CBase, using it as a template argument:

 class CDerived : public CBase<CDerived> { public: CDerived () {} }; 

I have a library that is structured so much, and so far this library has been created statically, and everything is in order. But now I want to change it to a dynamic library, so I added the export / import keyword for the derived class:

 #if defined(BUILD_LIBRARY) # define EXPORT __declspec(dllexport) #else # define EXPORT __declspec(dllimport) #endif class EXPORT CDerived : public CBase<CDerived> { public: CDerived () {} }; 

This builds and links are fine, but as soon as I use CDerived in the executable, I get linker errors in CBase. No references to any of the CBase methods or constructors were found.

I read a lot about exporting a specialization template, but that didn't help. It looks like this scenario is generally solvable, but since my derived class is also a template argument, a problem may arise.

Can someone tell me if this special case can be exported or is it not possible at all?

+6
source share

All Articles