博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 运算符重载<<
阅读量:4562 次
发布时间:2019-06-08

本文共 722 字,大约阅读时间需要 2 分钟。

1 #include 
2 using namespace std; 3 4 class Good 5 { 6 public: 7 int member; 8 Good(int a): member(a) 9 {10 cout << "调用构造" << endl;11 }12 void show()13 {14 cout << member << endl;15 }16 Good operator+(const Good& obj)17 {18 return Good(member - obj.member);19 }20 21 friend ostream& operator<<(ostream& os, Good& obj)22 {23 os << obj.member << "运算符重载" << endl;24 25 return os; //这句话关键,便于重复调用 26 }27 };28 29 int main(int argc, char *argv[])30 {31 Good a(10), b(20);32 Good c = a + b;33 cout << c;34 c.show();35 return 0;36 }

 

转载于:https://www.cnblogs.com/autumoonchina/p/3627119.html

你可能感兴趣的文章
跨进程访问共享内存的权限问题
查看>>
AD管理中心
查看>>
地图定位
查看>>
笑话收集
查看>>
c++相关网站
查看>>
java8-2 多态的概述
查看>>
有符号的整数翻转
查看>>
【转】js中cookie的使用详细分析
查看>>
linux shell学习笔记
查看>>
打印杨辉三角
查看>>
Linux入门配置之一
查看>>
素数筛选实现
查看>>
sass的使用
查看>>
第2章 感知器分类算法 2-1 分类算法的总体描述
查看>>
Reactjs+BootStrap开发自制编程语言Monkey的编译器:创建简易的页面IDE
查看>>
第九章 模板与群体数据 导学
查看>>
RecyclerView的2种监听方式
查看>>
java语言基础第三讲作业
查看>>
iOS-Swift中的递增(++)和递减(--)被取消的原因
查看>>
Walk 解题报告
查看>>