I am still getting the hang of polymorphism, and I wanted to see if you all could point out the error I am making, and make sence of the linker error I am getting as a result.
In summary, I have a parent class that has a virtual function that I want to override in the child classes, but when doing the approach below I get a linker error in the object files.
P.S. I am simply trying to reach one of the sub-classes members from the parent class, but it does not have a function to retrieve that sub class member, and if I try to write one the parent class has no idea what or who that subclass member is, so I went about it using the virtual function.
AGAM.h:
//------------- Parent class header file ( also this class is instantiated so not abstract ) ---
virtual std::string getHardwareName(); //original declaration
AGAM.cpp:
//----------- Parent cpp file ----------------------------
std::string getHardwareName() // parent class definition
{
return NULL;
}
TUI.h:
//-------------- child class header file ---------
std::string getHardwareName(); //child class override
TUI.cpp:
//--------------- child class cpp file ----------
std::string getHardwareName(){ // override definition
return mBoardName;
}
I am using MS Visual Studio, and below is the linking errors I am getting:
Error LNK2001 unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits,class std::allocator > __thiscall AGAM::getHardwareName(void)" (?getHardwareName@AnalogGroupAssignmentManager@Boards@TIU@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) TOC C:\path\to\object\file.obj) 1
And I get the same error for the child obj
files.