Reputation: 633
I'm trying to compile the Microsoft Sample "Overloading the << Operator for Your Own Classes" but get the following link error:
error LNK1169: one or more multiply defined symbols found
error LNK2005: "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class Date const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVDate@@@Z) already defined in Date.obj
Anybody any idea why this is not compiling?
Upvotes: 1
Views: 647
Reputation: 627
For me this error was was related to multiple definitions and i solved it following a recommendation from Microsoft. In project properties=>Linker=>Command Line=> Additional Options text box add a command "/FORCE:MULTIPLE". This solved my problem. (https://msdn.microsoft.com/en-us/library/70abkas3.aspx)
Upvotes: 0
Reputation: 258618
If you have the definition of the operator inside a header file, you have to declare it inline
, otherwise it will be defined in all translation units that include that header.
But it's probably better to move it to a implementation file, unless you have strong reasons for having it in a header.
Upvotes: 4