首页 > 编程语言 > 详细

vs2010编译C++ 运算符冲在

时间:2015-05-23 12:49:00      阅读:232      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!