C++中运算符重载
来源:互联网 发布:oracle not like 优化 编辑:程序博客网 时间:2024/06/14 06:38
下面代码实现+、()、=的运算符重载,仅供参考。
#include <iostream>class Body{public: Body(int a = 0):m_a(a) {} ~Body() {}#include <iostream>class Body{public: Body(int a = 0):m_a(a) {} ~Body() {} Body(const Body& a) { this -> m_a = a.m_a; } // +运算符重载 Body operator+(const Body& a) { Body bd; bd.m_a = this -> m_a + a.m_a; return bd; } // ()运算符重载 int operator()(int i) { return this -> m_a + i; } // =运算符重载 Body& operator=(const Body& a) { this -> m_a = a.m_a; return *this; } int get() { return m_a; }private: int m_a;};int main(int argc, char** args) { Body a(1); Body b(100); Body result = a = b; std::cout << "a: " << result.get() << std::endl; std::cout << (a + b).get() << std::endl; std::cout << a(999) << std::endl; return 0;}
0 0
- 矩形类中运算符重载【C++】
- 矩形类中运算符重载【C++】
- 矩形类中运算符重载【C++】
- 矩形类中运算符重载【C++】
- C++-运算符重载
- [C++]重载运算符
- C#:运算符重载
- c++-++运算符重载
- C++:重载运算符
- 运算符重载(C++)
- [c++]运算符重载
- 【C++】运算符重载
- C++--------------------------------------------运算符重载
- C#:运算符重载
- C++:运算符重载
- C++:运算符重载
- C#:运算符重载
- [C++]运算符重载
- spring事务管理几种方式(转)
- UML活动图
- 哈夫曼编码/译码器
- [参考+理解]hibernate的查询和性能调优
- 面板Ext.Panel使用
- C++中运算符重载
- jquery 页面循环倒计时
- Spring-web源码解析之HttpRequestHandler
- 虚拟机下centos 6.4安装超级详细图解教程(64位)
- 指针用于将函数中形参的值传递给实参
- 【设计模式】单例模式
- 基于surf特征点的图像局部图像抽取
- 破解myeclipse6.5
- MySQL 5.6 root密码丢失,使用mysqld --skip-grant-tables