C++ 重载输出运算符<<

来源:互联网 发布:少林足球 知乎 编辑:程序博客网 时间:2024/06/16 06:27


#pragma once#include <iostream>class MyPoint2f{public:MyPoint2f();MyPoint2f(float a,float b):x(a),y(b){}~MyPoint2f();bool operator < (const MyPoint2f &myPoint ) const{return x < myPoint.x;}friend std::ostream& operator << (std::ostream &os,const MyPoint2f &myPoint);float x;float y;};

#include "MyPoint2f.h"MyPoint2f::MyPoint2f(){}MyPoint2f::~MyPoint2f(){}std::ostream& operator <<(std::ostream &os,const MyPoint2f &myPoint){os << "[" << myPoint.x << "," << myPoint.y << "]";return os;}


0 0
原创粉丝点击