第十八章 23重载输出运算符

// 23重载输出运算符
/*
#include <iostream>
using namespace std;
class A
{
public:
	A(int x, int y){
	    rx = x;
		ry = y;
	}
//private:
	int rx;
	int ry;
};
ostream&operator<<(ostream&s, const A&c)
{
	s<<c.rx<<" ";
	s<<c.ry<<endl;
	return s;
};

int main()
{
	A a(3,4), b(5,6);
    cout<<a<<b<<endl;
    return 0;
	//这就是返回ostream类对象cout的作用,按位左移动算符<<可以连续使用,由于每次都会返回一个cout,所以中间不用加cout
	//注意:由于cout是另一个类ostream的对像,ostream类没有公有和复制构造函数,因此函数无法调用该类的复制构造函数复制对象,必须按引用方式按受ostream的对像并且按引用方式返因ostream对象

}*/

  

posted @ 2012-09-24 22:27  简单--生活  阅读(185)  评论(0编辑  收藏  举报
简单--生活(CSDN)