error LNK2001: unresolved external symbol C++

c++, inheritance, linker, visual-c++

Solution

Have you implemented `X()` in `Base`? You need to do that, or make it pure virtual:

class Base
{
// code
virtual HRESULT X() = 0; //pure virtual. Base doesn't need to implement it.
//code
};

Also, your definition of `X()` in `Derived` looks wrong. You probable need something like this:

HRESULT Derived::X()
{
// definition of Derived here. 
}

Problem

IN my VC++ code which was compiling fine earlier, I have added a function X() like this: ``` In the file BaseCollection.h class Base { // code virtual HRESULT X(); //code }; IN the file DerivedCollection.h class Derived:public Base { HRESULT X(); } In the file DerivedCollection.cpp HRESULT Derived::X { // definition of Derived here. } ``` Have included the header files also properly in the .cpp file. But still I don't understand for what reason I am getting the link error: error LNK2001: unresolved external symbol "public: virtual long __thiscall Base::X()" (?X@Base@@UAEJI@Z) I am really trying hard to fix this bug. Can anyone kindly help me in getting this issue resolved. Thanks a lot in advance.

Original source