我尝试在 C++ 中重载运算符,但我遇到了一些困难。这是我在课堂上的内容:
ostream & operator <<(ostream & s)
{
s << w();
return s;
}
string w()
{
stringstream ss;
string str;
for (int i=n-1; i>=0; i--)
{
if (i==n-1)
{
ss<<tablica[i] << "x^" << i;
}
else
{
if (tablica[i]<eps && tablica[i]>-eps) ss <<"+" << +tablica[i]<< "x^" << i;
else if (tablica[i]<eps)ss << tablica[i]<< "x^" << i;
if(tablica[i]>eps) ss <<"+" << +tablica[i]<< "x^" << i;
}
}
ss >> str;
return str;
}
我正在尝试这样使用:
cout << p << endl;
错误:no match for 'operator<<' in 'std::cout << p
这是我的整个程序代码:http ://codepad.org/xBijPMCp