根據書中的解釋,應該這樣寫代碼:
inline const Rational operator*(const Rational& lhs, const Rational& rhs)
{
return Rational(lhs.n * rhs.n, lhs.n*rhs.d);
}
按照這個例子,我自己寫了個代碼測驗一下:
inline const string& copyA(const string& srcStr)
{
return string(srcStr+"world");
}
int main()
{
string str1("hello");
string str2 = copyA(str1);
cout<<str2<<endl;
return 0;
}
結果沒有輸出,到底該怎么寫呢?
uj5u.com熱心網友回復:
直接回傳物件而且一般也不會回傳const 物件的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/88623.html
標籤:基礎類
