设为首页 加入收藏

TOP

c++重载ostream的实现
2015-07-20 17:39:45 来源: 作者: 【 】 浏览:3
Tags:重载 ostream 实现
#include 
  
   
using namespace std;

class Point{
public:
	Point(int _x = 0, int _y = 0, int _z = 0):x(_x), y(_y), z(_z){}
	Point(){}
	~Point(){}
	friend ostream& operator<<(ostream &os, const Point &pd);
private:
	int x;
	int y;
	int z;
};

ostream& operator<<(ostream &os, const Point &pd){
	os << pd.x<<" "<
   
    主要的注意点就是,要把函数作为class Point的友元函数,在类的外面进行定义,此外要注意return os,达到链式的作用。 
   
  
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇九度OJ1004 Median 下一篇UVALive-6656-Watching the Kanga..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)