I have been coding on VC++ 2015 platform and I always get unresolved external symbol error on non-overridden base class functions. Here is the example :
//BaseClass.h
template<class T>
class BaseClass {
public:
T* setRootPath(std::string&& rootPath);
....
}
//Implementations are in BaseClass.cpp
//ChildClass.h
class ChildClass:public BaseClass<ChildClass> {
public:
ChildClass* setWidth(const int width);
//No redefinition of "setRootPath" and hope not necessary
....
}
//Implementations are in ChildClass.cpp and i included BaseClass.cpp in this file as well
When I compile this code it throws no error. On the other hand during linkage time it says that it cannot find the required symbol for setRootPath with appropriate templating. Why can't it find "ChildClass* setRootPath(std::string&& rootPath)
" function?
What I want to ask is that "Should I declare the function with an appropriate return type in ChildClass while I want to use the very same definition from the BaseClass"?
The error thrown by MSVC is :
error LNK2001: unresolved external symbol "public: class ChildClass * __cdecl BaseClass<class ChildClass>::setRootPath(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &&)" (?setRootPath@?$BaseClass@VChildClass@3@$$QEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
Thanks for your help in advance.