首页 > 编程知识 正文

不能进行重载的运算符,c语言实现函数重载

时间:2023-05-03 16:44:09 阅读:119757 作者:507

ostream是标准的输出流,经常使用cout直接输出,但我认为cout不会直接打印类

下面的代码允许直接将符号重载到“”并直接打印类

Point.h

# ifndef _ point _ h _ # define _ point _ h _ # includeiostreamusingnamespacestd; class point { public : friendostreamoperator (ostream OS,const Point p ); point(intx,int y ); private: int m_iX; int m_iY; (; #endif Point.cpp

# include iostream # include ' point.h ' ostream operator (ostream OS, const Point p ) const修饰的表面是输入型参数(returnOS'x='p.)//返回的是cout point } point :3360 point (intx,int y ) 3360

#include'point.h'intmain(void ) pointp ) 2,1 ); cout p; //安装系统的打印返回0; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。