LNK2001 error: C ++ unresolved external character

In my VC ++ code that used to compile, I added the X () function as follows:

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. 
}

Also included header files in the .cpp file. But still, I don’t understand why I get the error message:

error LNK2001: unresolved external symbol "public: virtual long __thiscall Base :: X ()" (? X @Base @@ UAEJI @Z)

I am really trying to fix this error. Can anyone help me in solving this problem. Thank you very much in advance.

+3
source share
2 answers

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

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

, X() Derived . , , - :

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

X:

HRESULT Base::X()
{
// definition of X 
}

Derived::X(), virtual.

+2

All Articles