最简单的重载加法运算符

#include<iostream>
#include<string.h>
using namespace std;
class String{
        public:
                int a;
                String &operator + (const String &rhs);
                String(int b){
                    a=b;
                }
};

String &String :: operator+(const String &rhs){         //重载加法运算
        cout<<"a+b"<<endl;
        return *this;
}

int main(){
    String a(1);
    String b(2);
    a+b;
    return 0;
}

posted @ 2017-04-11 20:41  倾耳听  阅读(651)  评论(0编辑  收藏  举报