作者:
hunandy14 (Charlott.HonG)
2016-05-31 19:37:04請問樣板類別的運算子重載該怎麼寫呢
參考自 http://goo.gl/0lihn8
我試著在自己加上樣板結果出來編不過
程式碼 https://gist.github.com/anonymous/0f2c51e9fb4d9a85406e39044eb370a4
註解的地方有[17][36][80] (錯誤的地方)
我想要做分數的相加,用frac儲存分數
frac<double> a(1,3);
frac<double> b(1,2);
frac<double> temp;
temp=a+b; //temp=5/6
編譯使用G++,錯誤訊息是
error.cpp:17:48: error: 'frac<T1> frac<T1>::operator+(const frac<T1>&, const
frac<T1>&)' must take either zero or one argument
frac operator+(const frac &a, const frac &b);
^
error.cpp:82:1: error: 'frac<T1>::frac' names the constructor, not the type
frac<T1>::frac operator+(const frac &a, const frac &b){
^