error LNK2005的解决

Bid.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>buildbidpage.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>Bid.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>buildbidpage.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>Categories.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>Category.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>Listing.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>main.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>processrequest.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>bidhistory.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>buildpage.obj : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Bid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVBid@@@Z) 已经在 Advertisement.obj 中定义 1>./Debug/main.exe : fatal error LNK1169: 找到一个或多个多重定义的符号 

 

网上说了各种解决方案,都不适合自己的情况,仔细检查之后,发觉造成这个错误的原因是 istream &operator>>(istream &stream, Bid &b){ string email; float amount; int quantity; Date date; stream>>email>>amount>>quantity>>date; b.setEmail(email); b.setAmount(amount); b.setQuantity(quantity); b.setDate(date); return stream; };

上面这个函数的声明了定义写在了Bid.h这个头文件中,而其它的函数的定义 是写在.cpp文件 中,把这个操作符重载的方法体写在.cpp文件即可。

 

你可能感兴趣的:(Date,struct,Stream,basic,Class,email)