> I have been programming C++ for years, but mostly with other tools. I
> do not recall encountering this issue, e.g. with Borland's C++ Builder
[quoted text clipped - 19 lines]
> Is there a way to avoid such an issue without using /force (and the
> concommitant transformation of the linker error into a warning)?

Signature
David Wilkinson
Visual C++ MVP
> > I have been programming C++ for years, but mostly with other tools. I
> > do not recall encountering this issue, e.g. with Borland's C++ Builder
[quoted text clipped - 31 lines]
>
> - Show quoted text -
Hi David
The first is:
Error 3 error LNK2005: "class std::basic_ostream<char,struct
std::char_traits<char> > & __cdecl operator<<(class
std::basic_ostream<char,struct std::char_traits<char> > &,class
investment_holding const &)" (??6@YAAAV?$basic_ostream@DU?
$char_traits@D@std@@@std@@AAV01@ABVinvestment_holding@@@Z) already
defined in MemoryBasedPortfolio.obj portfolio_snapshot.obj
The second is:
Error 4 error LNK2005: "class std::basic_ostream<char,struct
std::char_traits<char> > & __cdecl operator<<(class
std::basic_ostream<char,struct std::char_traits<char> > &,class
investment_holding const &)" (??6@YAAAV?$basic_ostream@DU?
$char_traits@D@std@@@std@@AAV01@ABVinvestment_holding@@@Z) already
defined in MemoryBasedPortfolio.obj portfolio.obj
And of course these are followed by:
Error 5 fatal error LNK1169: one or more multiply defined symbols
found K:\MSVSProjects\MemoryBasedPortfolio\Debug
\MemoryBasedPortfolio.exe 1
The investment_holding compilation unit has an operator<<, as do a
couple others that happen to contain a container (usually an STL set)
of investment_holding instances.
Any ideas?
I can show you the operator<<() overloads, if that would help.
Thanks
Ted
David Wilkinson - 24 Jul 2008 11:14 GMT
>>> I have been programming C++ for years, but mostly with other tools. �I
>>> do not recall encountering this issue, e.g. with Borland's C++ Builder
[quoted text clipped - 63 lines]
>
> Thanks
Ted:
These errors have to do with your own code, so it is "premature" to blame the
compiler.
If these operator <<'s are defined in the header file but not inside the class
definition, then they must be declared inline, or moved to the implementation file.

Signature
David Wilkinson
Visual C++ MVP