当前位置:编程学习 > C/C++ >>

c++的一个友元重载编译出现错误

#include <iostream>
using namespace std;
class Complex{
public:
 Complex(){real=0;imag=0;}
 Complex(double r,double i):real(r),imag(i){}
 void display();
 friend Complex operator +(Complex &c1,Complex &c2);       //这里那错了?
private:
 double real;
 double imag;
};
void Complex::display(){
 cout<<real<<endl;
}
Complex operator +(Complex&c1,Complex&c2){
 return Complex(c1.real+c2.real,c1.imag+c2.imag);
}

int main(){
 Complex c1(3,4),c2(5,7),c3;
 c3=c1+c2;
 c1.display();
 c3.display();
 return 0;
}

提示出错:

E:\studying\c de\重载.cpp(8) : 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.

追问:这是为什么呢?
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,