标题:[求助]关于操作符的重载问题
取消只看楼主
海子星竹
Rank: 1
等 级:新手上路
威 望:1
帖 子:58
专家分:0
注 册:2007-9-4
 问题点数:0 回复次数:1 
[求助]关于操作符的重载问题
#include <iostream>
using namespace std;

class Test
{
public:
Test(int a)
{
Test::a = a;
}
Test operator + (Test &temp) //就是这个函数
{
Test result(this->a + temp.a);
return result;
}
public:
int a;
};

int main()
{
Test a(100);
a = a + Test(10);
a = Test(10) + a;
cout<<a.a<<endl;
a = 50 + 1;
cout<<a.a<<endl;
system("pause");
return 0;
}
搜索更多相关主题的帖子: 操作符 重载 
2007-09-14 12:10
海子星竹
Rank: 1
等 级:新手上路
威 望:1
帖 子:58
专家分:0
注 册:2007-9-4
得分:0 

理解
谢谢版主

2007-09-14 18:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-169903-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.304203 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved