首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

帮看下这个有关问题出了什么错

2012-02-09 
帮看下这个问题出了什么错#includeiostreamusing namespace stdclass A{friend A operator+(const A& t

帮看下这个问题出了什么错
#include<iostream>
using namespace std;

class A
{
friend A operator+(const A& t1,const A &t2)
{
A ret(t1);
ret+=t2;
return ret;
}
public:
int a;
A(int i):a(i){}
A& operator+=(const A &t1)
{
a=a+t1.a;
return *this;
}
};

int main()
{
A a(1),b(2);
a=a+b;
cout<<a.a<<endl;
return 0;
}

我用的是VC6.0编译器 怎么通不过 哪个帮看下出了什么问题

[解决办法]
VC9直接通过
你还是升级编译器吧,VC6对友元支持有bug
[解决办法]
记得,要在vc6.0下面用友元的话,不能用标准命名空间;要用<iostream.h>试试吧

热点排行
Bad Request.