码迷,mamicode.com
首页 > 编程语言 > 详细

vs2010编译C++ 运算符冲在

时间:2015-05-23 12:50:16      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

// 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;
}

 

vs2010编译C++ 运算符冲在

标签:

原文地址:http://www.cnblogs.com/bksqmy/p/4523968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!