#2
rjsp2023-04-28 14:07
|
程序代码:
class hgold
{
private:
int f_gold;
public:
hgold(int val);
int get_gold();
hgold(hgold& c_hgold);
std::ostream& operator<<(hgold c_gold);
};
hgold::hgold(int val)
{
f_gold = val+500;
}
int hgold::get_gold()
{
return f_gold;
}
std::ostream& hgold::operator<<(hgold c_gold)
{
std::cout << c_gold.get_gold();
return std::cout;
}
int main()
{
hgold gold{100};
std::cout << "gold的数量为===>" << gold;
}
这样写报错了,不知道为什么,我把左移写成全局函数就行,写成成员函数就错了
[此贴子已经被作者于2023-4-28 11:43编辑过]