C++ operator overload -- 操作符重载 2011-12-13 14:18:29 分类: C/C++ 操作符重载有两种方式,一是以成员函数方式重载,另一种是全局函数. 先看例子 #include <iostream> #include <string> using namespace std; /* defualt operator= differ from my own one. * assign 0 or 1 to TEST_EQ, look the dif
重载操作符的定义 这篇博客是对 重载操作符 的一个概要性的介绍. 重载操作符是C++语言的高级功能,当我们写一个类的时候,可以根据需要学一个重载操作符,如果 不需要,我们可以不写. 大量的操作符都可以重载.可以重载的操作符有42个. 有4个操作符是不可以重载的. 下面写几个例子,来看看,如何重载操作符. #include <iostream> using namespace std; int main(){ int a, b; a = 12; b = 9; cout << a +