大一c++友元函数声明部分内部编译器出错不知道什么原因 20
这是部分代码:#include<iostream>usingnamespacestd;classcomplex{doublereal;doubleimage;public...
这是部分代码:
#include<iostream>
using namespace std;
class complex{
double real;
double image;
public:
complex(double real=0,double image =0){};
void input(){
cout<<"请输入该复数的实部"<<endl;
cin>>real;
cout<<"请输入该复数的虚部:"<<endl;
cin>>image;
}
void output(){
cout<<"所求复数为:"<<"z="<<real<<"+"<<image<<"i"<<endl;
}
friend complex operator+(complex,complex);
friend complex operator-(complex,complex);
friend complex operator*(complex,complex);
friend complex operator/(complex,complex);
friend complex operator*=(complex,complex);
friend complex operator/=(complex,complex);
}; 展开
#include<iostream>
using namespace std;
class complex{
double real;
double image;
public:
complex(double real=0,double image =0){};
void input(){
cout<<"请输入该复数的实部"<<endl;
cin>>real;
cout<<"请输入该复数的虚部:"<<endl;
cin>>image;
}
void output(){
cout<<"所求复数为:"<<"z="<<real<<"+"<<image<<"i"<<endl;
}
friend complex operator+(complex,complex);
friend complex operator-(complex,complex);
friend complex operator*(complex,complex);
friend complex operator/(complex,complex);
friend complex operator*=(complex,complex);
friend complex operator/=(complex,complex);
}; 展开
2个回答
展开全部
如果编译器是vc++6.0之类的,可能是编译器的问题,而不是代码本身不对。
可以尝试把#include<iostream>
using namespace std;
这两行改为#include<iostream.h>
可以尝试把#include<iostream>
using namespace std;
这两行改为#include<iostream.h>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询