views:

266

answers:

2

I have a List of type Node. I want to set a temporary Node equal to the Node at the front of the List but I keep getting a Linker Error:

class Node
{ 
   public:
      Node();
      Node& operator = (const Node& n);
};

1>Linking... 1>main.obj : error LNK2019: unresolved external symbol "public: class Node & __thiscall Node::operator=(class Node const &)" (??4Node@@QAEAAV0@ABV0@@Z) referenced in function "void __cdecl fillScan(int,class std::list >)" (?fillScan@@YAXHV?$list@VNode@@V?$allocator@VNode@@@std@@@std@@@Z) 1>C:\Users\Aaron McKellar\Documents\School Stuff\CS445\Test\Debug\Test.exe : fatal error LNK1120: 1 unresolved externals

Thanks in advance!

+2  A: 

You only showed the declaration of operator=, not the definition. Either you didn't supply a definition or the linker can't find it.

Well, I should say: The linker definitely can't find the definition for operator=. Either that's because you forgot to supply one or because your project/Makefile is set up incorrectly.

sepp2k
please view my comments above
Aaron McKellar
A: 

You need to supply a definition for operator=, of course:

Node& Node::operator=(const Node& n) {

     // 'copy' semantics for Node
}

Note that the compiler generates the assignment operator by itself using memberwise copy if none is provided. Use the compiler-generated operator if sufficient.

Alexander Gessler
please view my comments above
Aaron McKellar