编程语言
首页 > 编程语言> > C++运算符重载

C++运算符重载

作者:互联网

注意事项

以全局函数的形式重载:四则运算符号、逻辑判断符号、流运算符号
+ - * / == != < > <= >= << >>

以成员函数的形式重载:赋值类符号、自增符号、型强制转换符号、成员访问符号
= += -= *= /= ++ -- () [] ->

不限形式重载:内存管理符号
new delete new[] delete[]

friend T operator+(const T &c1, const T &c2);
friend T operator-(const T &c1, const T &c2);
friend T operator*(const T &c1, const T &c2);
friend T operator/(const T &c1, const T &c2);


friend bool operator==(const T &c1, const T &c2);
friend bool operator!=(const T &c1, const T &c2);


friend istream &operator>>(T & in, T &c);
friend ostream &operator<<(T & out, T &c);


T &operator+=(const T &c);
T &operator-=(const T &c);
T &operator*=(const T &c);
T &operator/=(const T &c);


T operator++();  	// ++ i
T operator++(int);  // i ++
T operator--();		// -- i
T operator--(int);	// i --


operator double(); // 重载强制类型转换运算符时,不需要指定返回值类型


T &operator[](int);
const T &operator[](int) const;

标签:const,C++,运算符,operator,重载,c2,c1,friend
来源: https://www.cnblogs.com/ivvodocuments/p/16561451.html