You receive a link error when you build an application that contains a base class in Visual C++

When building an application that contains a base class with a pure virtual operator= function and a class derived from the base class with a defined operator= function, a following link error is generated for the base class’s operator=:

error LNK2001: unresolved external symbol

This also occurs if the classes reside in a DLL and are declared with the __declspec( dllexport ) storage-class attribute.

In Visual C++ .NET you will receive the following error message:

LNK2019: unresolved external symbol


This behavior is by design. The assignment operator is not inherited. Normal inheritance rules do not apply, and declaring it pure virtual does not have the usual affect.


Since operator= is not inherited, any declaration of operator= in the base class is unused and unnecessary. Do not declare the operator= in the base class.


When built, the following code sample will generate the discussed LNK2001 error. Comment the declaration of the operator=() member in the base class to resolve.

Sample Code

/* Compile options needed: none

class A
public :
   // To workaround LNK2001, comment the following line.
   virtual const A& operator=( const A& f ) = 0;

class B : public A
public :
   const A& operator=( const A& g ) {return g;}

B aB1, aB2;

void main( void )
   aB2 = aB1;


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply

To prove that you're not a bot, enter this code
Anti-Spam Image