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.
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.
}
You're never defining the function X
:
HRESULT Base::X()
{
// definition of X
}
You'll also need a definition for Derived::X()
since that too is virtual
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With