开发者

C++ Linker Error involving operator overload function

I have a List of type Node. I want to set a temporary Node equal to the Node at the front of the List, as follows:

class Node
{ 
   public:
      Node();
      Node& op开发者_开发技巧erator = (const Node& n);
};

but I keep getting a Linker Error:

Linking...

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)

C:\Users\Aaron McKellar\Documents\School Stuff\CS445\Test\Debug\Test.exe : fatal error LNK1120: 1 unresolved externals

Thanks in advance!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜