![](https://img-blog.csdnimg.cn/20190918140213434.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
----------运算符重载
寂寂寂寂寂蝶丶
这个作者很懒,什么都没留下…
展开
-
单目运算符-作为成员重载
单目运算符-作为成员重载 #include "stdafx.h" #include using namespace std; //单目运算符重载 //M# #M ++a a++ //operator#(L); 作友元 //L.operator#(); 作成员 class Complex { public: Complex(float x = 0, float y = 0) :_x(转载 2017-12-08 12:36:24 · 639 阅读 · 0 评论 -
双目运算符+=的重载
双目运算符+=的重载 #include "stdafx.h" #include using namespace std; #if 0 通常情况下: 单目 : 重载为成员的话,需要0个参数,重载为友元的时候需要一个参数 双目(+) 重载为成员的话,需要一个参数,重载为友元的时候需要俩个参数 friend Complex operator+(Complex &a, Complex转载 2017-12-07 17:15:29 · 1733 阅读 · 0 评论 -
智能指针
智能指针 #include "stdafx.h" #include using namespace std; #include //智能指针 class A { public: A() { cout << "A()" << endl; } ~A() { cout << "~A()" << endl; } void func() { cout << "s转载 2017-12-08 12:39:28 · 177 阅读 · 0 评论 -
new与delete的重载
new与delete的重载 #include "stdafx.h" #include using namespace std; #include #include //new 和delete的重载 //new new[] delete delete[] //适用于极个别情况需要定制的时候才用的到。一般很少用 //声明可以不加 参数 //void *operator new(size转载 2017-12-08 12:39:11 · 208 阅读 · 0 评论 -
重载函数操作符() 仿函数
重载函数操作符() 仿函数 #include "stdafx.h" #include using namespace std; #include #if 0 函数操作符(())-- - 仿函数 class 类名 { 返值类型 operator()(参数类型) 函数体 } #endif class Pow { public: int operator()(int转载 2017-12-08 12:38:29 · 260 阅读 · 0 评论 -
类型转换操作符函数
类型转换操作符函数 #include "stdafx.h" #include using namespace std; #include //用类型转换操作符函数进行转换(在自己的类中实现) class Point2D { public: Point2D(int x, int y) :_x(x), _y(y){} void dis() { cout << "(" <<转载 2017-12-08 12:38:08 · 220 阅读 · 0 评论 -
类型转换构造函数
类型转化构造函数 #include "stdafx.h" #include using namespace std; #include //用类型转换构造函数进行类型转换 class Point2D { public: Point2D(int x, int y) :_x(x), _y(y){} friend class Point3D; //设置友元类 private:转载 2017-12-08 12:37:46 · 307 阅读 · 0 评论 -
运算符重载的俩边为不同类的对象
运算符重载的俩边为不同类的对象 #include "stdafx.h" #include using namespace std; #include #if 0 运算符重载实践 结论: 1,一个操作符的左右操作数不一定是相同类型的对象, 这就涉及到将该操作符函数定义为谁的友元,谁的成员问题。 2,一个操作符函数,被声明为哪个类的成员,取决于 该函数的调用对象(通常是左操作数)。转载 2017-12-08 12:37:28 · 1014 阅读 · 0 评论 -
流输入>>、流输出<<作为友元重载
流输入>>、流输出 #include "stdafx.h" #include using namespace std; //流输入输出重载 class Complex { public: Complex(float x = 0, float y = 0) :_x(x), _y(y){} void dis() { cout << "(" << _x << "," << _y转载 2017-12-08 12:36:56 · 264 阅读 · 0 评论 -
单目运算符前++与后++的重载
单目运算符前++与后++的重载 #include "stdafx.h" #include using namespace std; //重载前++ 与 后++ //返回对象和引用:优先考虑返回引用 //返回类型加不加const:优先考虑加const类型 //运算符重载 按照基础数据类型的用法 class Complex { public: Complex(float x = 0,转载 2017-12-07 17:23:54 · 308 阅读 · 0 评论