帮看下这个问题出了什么错
#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>试试吧