vs2010编译C++ 运算符

// CTest.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

class str{
private:
    char s[80];
public:
    str(char c[]){
        strcpy(s,c);
    }
    str(){
    }
    str operator +(str c){//将运算符+号重载为成员函数
        strcat(s,c.s);
        return *this;
    }
    void display(){
        cout<<s<<endl;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    char s1[80],s2[80];
    gets(s1);
    gets(s2);
    str p(s1),q(s2),r;
    r = p + q;        //等价于 r=p.operator+(q);
    r.display();
    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/bksqmy/p/4523968.html