左移运算符重载
#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;
}