[問題] 還是把完整的問題寫出來好了
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
"C++ How to program 5ed" 11-17,創造一個 polynomial 的class
希望得到的正確結果:
上一個問題在各位前輩一語點醒之下破關了。
並且也再接再厲做出了operator + 以及 operator-
結果在要overload operator= 的時候出了問題...
--------------------以下是我的header file------------------------
class polynomial
{
friend ostream &operator<< (ostream & output, polynomial & pol)
{
pol.get_pol();
return output;
}
friend istream &operator>> (istream & input, polynomial & pol)
{
pol.set_pol();
return input;
}
public:
polynomial();
~polynomial();
void set_pol();
void get_pol();
polynomial &operator+ (const polynomial&);
polynomial &operator- (const polynomial&);
polynomial &operator* (const polynomial&);
polynomial &operator+=(const polynomial& poly)
{
*this = *this + poly;
return *this;
}
polynomial &operator-=(const polynomial& poly)
{
*this = *this - poly;
return *this;
}
polynomial &operator*=(const polynomial& poly)
{
*this = *this * poly;
return *this;
}
polynomial &operator= (const polynomial&);
private:
int terms;
int number;
int** temp;
int** real;
void arrange();
};
------------------------以下為有.CPP檔operator= 附近的段落----------------
polynomial &polynomial::operator= (const polynomial& pol){
delete [] real;
terms = pol.terms;
real = new int*[terms];
for(int t=0; t<terms; ++t){
real[t] = new int[2];
}
for (int t=0; t<terms; ++t){
real[t][0] = pol.real[t][0];
real[t][1] = pol.real[t][1];
}
return *this;
}
程式跑出來的錯誤結果:
`polynomial& polynomial::operator=(const
polynomial&)' and `polynomial& polynomial::operator=(const polynomial&)'
cannot be overloaded
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
Dev-C++
有問題的code: (請善用置底文標色功能)
如上,operator+ operator- 都OK啊...
補充說明:
這是1/25要交的作業...有點急就是了。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.57.147.96
推
01/21 09:48, , 1F
01/21 09:48, 1F
→
01/21 10:03, , 2F
01/21 10:03, 2F
→
01/21 10:03, , 3F
01/21 10:03, 3F
推
01/21 10:06, , 4F
01/21 10:06, 4F
→
01/21 10:07, , 5F
01/21 10:07, 5F
→
01/21 10:07, , 6F
01/21 10:07, 6F
推
01/21 10:08, , 7F
01/21 10:08, 7F
→
01/21 10:56, , 8F
01/21 10:56, 8F
以上感謝各位~!
※ 編輯: takua624 來自: 61.57.147.96 (01/21 11:12)
→
01/21 11:23, , 9F
01/21 11:23, 9F
→
01/21 13:55, , 10F
01/21 13:55, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章