重载的细节
#include <iostream>using namespace std;class A{ int b; public: A(int m=0):b(m){cout<<"one arg constructor"<<endl;} A(const A& another){ cout<<"const copy constuctor is called"<<endl; b=another.getvalue(); } A(A& another){ cout<<"not const copy constuctor is called"<<endl; b=another.getvalue(); } ~A(){cout<<this->getvalue()<<" destructor is called"<<endl;} int getvalue()const{return b;} A operator +(A& another){ cout<<"using +"<<endl; return A(b+another.getvalue()); } A& operator =(const A& another){ cout<<"using ="<<endl; b=another.getvalue(); return *this; } operator int(){ cout<<"A to int is called."<<endl; return getvalue(); } };int main(int argc, char *argv[]){ int m=3; A a=m,b=m+1; A d=a+b; cout<<"-------2-------"<<endl; d=a+b; cout<<"---------------"<<endl; return 0;}