illegal else without matching if可我找不出错误
#include <iostream>
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;};
void set(){cin>>real>>imag;}
bool operator==(Complex&c2);
void display();
double real;
double imag;
};
bool Complex::operator==(Complex&c2)
{
Complex c;
if(c.real==c2.real&&c.imag==c2.imag) return true;
else return false;
}
void Complex::display()
{
if(real==0)
{
if(imag!=0) cout<<imag<<"i,";
else cout<<"0,";
};
else
{
if(imag>0) cout<<real<<"+"<<imag<<"i,";
else if(imag<0) cout<<real<<imag<<"i,";
else cout<<real<<",";
};
}
int main()
{
Complex c1,c2;
c1.set();
c2.set();
while (c1.real!=0||c1.imag!=0||c2.real!=0||c2.imag!=0)
{
cout<<"a=";
c1.display();
cout<<"b=";
c2.display();
if (c1==c2) cout<<"a等于b"<<endl;
else
{
cout<<"a不等于b"<<endl;
};
c1.set();
c2.set();
}
return 0;
}
一直显示error C2181: illegal else without matching if
可我检查了好多遍也没检查出错误。。。到底是哪里出问题了。。不是都配对的好好的嘛~~~欲哭无泪 求救哇~~