我想聲明的過載,非友,非會員' - - 經營者在頭文件:重載運營商有太多的參數,Visual Studio的C++
Quad operator-(const Quad &qu1, const Quad &qu2);
但我得到:
"error C2804: binary 'operator -' has too many parameters"
此代碼是從書和問題聲明,我似乎無法解決它。謝謝你的幫助。
我想聲明的過載,非友,非會員' - - 經營者在頭文件:重載運營商有太多的參數,Visual Studio的C++
Quad operator-(const Quad &qu1, const Quad &qu2);
但我得到:
"error C2804: binary 'operator -' has too many parameters"
此代碼是從書和問題聲明,我似乎無法解決它。謝謝你的幫助。
類定義範圍內的二元運算符只能帶一個參數。
Quad operator-(const Quad &quRight)
{
Quad res;
res.x = this->x - quRight.x;
// all other components
// ...
return res;
}
或者你可以在類之外移動運算符重載。
OP在他的問題中確實說了「非成員」。 –
哦,對不起,錯過了 –
你可能是對的,但可能缺少一個左大括號,導致它在課堂上。 –
您可能需要顯示一些周圍的代碼 - 該行適用於VS2013中的一個簡單的'Quad'類。 –
只是猜測...你確定你已經把這個聲明放在Quad類的主體之外嗎? –