#include <iostream>
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<<" "<<pd.y<<" "<<pd.z;
	return os;
}
 
int main() {
	Point pd(1,2,3);
	cout<<pd;
	return 0;
}
基本的注意点就是。要把函数作为class Point的友元函数,在类的外面进行定义,此外要注意return os。达到链式的作用。

相关文章:

  • 2021-12-18
  • 1970-01-01
  • 2021-12-18
  • 2021-07-23
  • 2021-11-20
  • 2021-05-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-29
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-02-15
相关资源
相似解决方案