我一直在试图超载>>
和<<
运营商在C++中,我不断收到:C++重载>>和<<运营商
Error 2 error LNK2019: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class ArrayStorage &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@@@Z) referenced in function _main G:\Desktop\ACW\08227_ACW2_TestHarnessSolution\main.obj
我做它的方式是:
//.h file
friend ostream& operator<<(ostream &sout, ArrayStorage &Astor);
friend istream& operator>>(istream &sin, ArrayStorage &Astor);
//cpp file
ofstream& operator<< (ofstream &sout, ArrayStorage &astor)
{
astor.write(sout);
return sout;
}
ifstream& operator>> (ifstream &sin, ArrayStorage &astor)
{
astor.read(sin);
return sin;
}
我的一位朋友告诉我要将头文件中声明的“朋友”从头文件中移出,并将其移到课程外,但我仍然得到相同的错误。这可能很简单,但我无法弄清楚什么不起作用。
与原始问题无关,但我通常会期望'''采取对该类型的const引用。 – 2012-04-20 13:35:44