程序员社区

运算符重载之左移运算符重载

左移运算符重载

#include<iostream>
using namespace std;
class wood {
	friend ostream& operator<<(ostream& cout, wood& d);
public:
	wood(int num):num(num){}
private:
	int num;
};
//左移运算符重载只能用全局函数
ostream& operator<<(ostream& cout, wood& d)
{
	cout << "木头的数量为" << d.num << endl;
	return cout;
}
int main()
{
	wood d(100);
	cout << d << endl;
	return 0;
}

赞(0) 打赏
未经允许不得转载:IDEA激活码 » 运算符重载之左移运算符重载

相关推荐

  • 暂无文章

一个分享Java & Python知识的社区