我不懂得问题关于友元的问题
有一段程序,如下:
#include <iostream.h>
//using namespace std;
class CL
{
public:
int count;
CL operator=(CL obj);
friend CL operator+(CL ob, int i);
friend CL operator+(int i, CL ob);
};
CL CL::operator=(CL obj)
{
count = obj.count;
return *this;
}
//处理ob+int的运算
CL operator+(CL ob, int i)
{
CL temp;
temp.count = ob.count + i;
return temp;
}
//处理int +ob的运算
CL operator+(int i, CL ob)
{
CL temp;
temp.count = ob.count + i;
return temp;
}
int main()
{
CL o;
o.count = 10;
cout << o.count << " ";
o = 10 + o;
cout << o.count << " ";
o = o + 12;
cout << o.count;
return 0;
}
这么编译没有错误,但是我把头两行改为
#include <iostream>
using namespace std;
编译后出现以下错误:
--------------------Configuration: 友元函数重载1 - Win32 Debug--------------------
Compiling...
友元函数重载1.cpp
d:\documents and settings\administrator\桌面\友元函数重载1.cpp(9) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
友元函数重载1.obj - 1 error(s), 0 warning(s)
我想问,按照现在标准我的第二种写法没有错误,是不是哪里有问题,我是弄不懂了,我的C++很菜,还希望高手指点一二!