我想有一個非類成員重載的put運算符,它使用引用參數輸出汽車對象的信息。插入運算符的非成員函數形式
這裏是我的代碼:
ostream& operator<<(ostream& os, Car& p)
{
os << "For a car make " << p.get_make() << ", " << p.get_year()<< ", the price is $" << p.get_price() << endl;
return os;
}
我得到一個錯誤std::ostream& Car::operator<<(std::ostream&, Car&)' must take exactly one argument
不允許我有車作爲參數?
謝謝。
只是聲明函數是類的朋友(即Car類) – rajesh6115