using namespace std;
class Complex
{public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";c3.display();
}
我在VC6.0下写的,可编译后,提示,编译器错误!怎么办呢?
17 个解决方案
#1
#include<iostream.h>
class Complex
{
public:
Complex()
{
real = 0;
imag = 0;
}
Complex(double r,double i)
{
real = r;
imag = i;
}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
void Complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3 = c1 + c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
class Complex
{
public:
Complex()
{
real = 0;
imag = 0;
}
Complex(double r,double i)
{
real = r;
imag = i;
}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
void Complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3 = c1 + c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
#2
Complex operator + (Complex &c1,Complex &c2)
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
#3
楼上的真强,你可以做白盒测试了,呵呵~~~~
#4
谢谢,楼上的兄弟!!
我真粗心!
我真粗心!
#5
学习学习....
#6
#include<iostream.h> //改为旧式头文件,
//using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<"i)"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";c3.display();
return 0;
}
//using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<"i)"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";c3.display();
return 0;
}
#7
Complex operator + (Complex &c1,Complex &c2)
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
同意
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
同意
#8
为什么,头文件的定义,会有区别讷?请问高人解释一下讷~~~~
#9
不理解楼上的话
#10
呵呵,不明白什么问题
#11
同意2楼
#12
用#include<iostream.h> 和用 #include<iostream> using namespace std
两者的区别何在讷?是不是与编译器有关?
两者的区别何在讷?是不是与编译器有关?
#13
#invlude<iostream.h>
与
#include<iostream>
use namespace std;
是相同的。。
与
#include<iostream>
use namespace std;
是相同的。。
#14
呵呵,我将你的程序的小错误改了改:
#include<iostream>
using namespace std;
class Complex
{public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<")"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
#include<iostream>
using namespace std;
class Complex
{public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<")"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
#15
#include <iostream.h>是旧式头文件,按理说这里改用新头文件不会出现错误,但是问题恰恰是用新头文件带来的内部编译错误。这可能是个例外吧
#16
同意上楼的观点,基本上那就是error的根本所在.
现简单一说<iostream.h>和<iostream>的区别:
1. .h格式的头文件在98年9月份被标准委员会抛弃.(尽管现在还是大行其道)
2. iostream.h只支持窄字符集,iostream则支持窄/宽字符集。
3. iostream组件全部放入namespace std中,防止了名字污染。
这就是为什么再用#include<iostream>时总要加个using namespace std;的原因.
4. 新标准对iostream作了很多的改动,接口和实现都有了变化。
少了.h却多了更多的内涵.真是简约而不简单啊:)
谢谢
现简单一说<iostream.h>和<iostream>的区别:
1. .h格式的头文件在98年9月份被标准委员会抛弃.(尽管现在还是大行其道)
2. iostream.h只支持窄字符集,iostream则支持窄/宽字符集。
3. iostream组件全部放入namespace std中,防止了名字污染。
这就是为什么再用#include<iostream>时总要加个using namespace std;的原因.
4. 新标准对iostream作了很多的改动,接口和实现都有了变化。
少了.h却多了更多的内涵.真是简约而不简单啊:)
谢谢
#17
#include <iostream.h>是旧式头文件。
#include <iostream>是标准的 规范的。
#include <iostream>是标准的 规范的。
#1
#include<iostream.h>
class Complex
{
public:
Complex()
{
real = 0;
imag = 0;
}
Complex(double r,double i)
{
real = r;
imag = i;
}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
void Complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3 = c1 + c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
class Complex
{
public:
Complex()
{
real = 0;
imag = 0;
}
Complex(double r,double i)
{
real = r;
imag = i;
}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
void Complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3 = c1 + c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
#2
Complex operator + (Complex &c1,Complex &c2)
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
#3
楼上的真强,你可以做白盒测试了,呵呵~~~~
#4
谢谢,楼上的兄弟!!
我真粗心!
我真粗心!
#5
学习学习....
#6
#include<iostream.h> //改为旧式头文件,
//using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<"i)"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";c3.display();
return 0;
}
//using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<"i)"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";c3.display();
return 0;
}
#7
Complex operator + (Complex &c1,Complex &c2)
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
同意
{ return Compex(c1.real+c2.real,c1.imag+c2.imag);} // compex 拼错了.
void Complex::display()
{cout<<"("<<real<<","<<img<<"i)"<<endl;} // img 拼错了.
同意
#8
为什么,头文件的定义,会有区别讷?请问高人解释一下讷~~~~
#9
不理解楼上的话
#10
呵呵,不明白什么问题
#11
同意2楼
#12
用#include<iostream.h> 和用 #include<iostream> using namespace std
两者的区别何在讷?是不是与编译器有关?
两者的区别何在讷?是不是与编译器有关?
#13
#invlude<iostream.h>
与
#include<iostream>
use namespace std;
是相同的。。
与
#include<iostream>
use namespace std;
是相同的。。
#14
呵呵,我将你的程序的小错误改了改:
#include<iostream>
using namespace std;
class Complex
{public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<")"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
#include<iostream>
using namespace std;
class Complex
{public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator + (Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{ return Complex(c1.real+c2.real,c1.imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<")"<<endl;}
int main()
{
Complex c1(2,4),c2(3,55),c3;
c3=c1+c2;
cout<<"c1+c2=";
c3.display();
return 0;
}
#15
#include <iostream.h>是旧式头文件,按理说这里改用新头文件不会出现错误,但是问题恰恰是用新头文件带来的内部编译错误。这可能是个例外吧
#16
同意上楼的观点,基本上那就是error的根本所在.
现简单一说<iostream.h>和<iostream>的区别:
1. .h格式的头文件在98年9月份被标准委员会抛弃.(尽管现在还是大行其道)
2. iostream.h只支持窄字符集,iostream则支持窄/宽字符集。
3. iostream组件全部放入namespace std中,防止了名字污染。
这就是为什么再用#include<iostream>时总要加个using namespace std;的原因.
4. 新标准对iostream作了很多的改动,接口和实现都有了变化。
少了.h却多了更多的内涵.真是简约而不简单啊:)
谢谢
现简单一说<iostream.h>和<iostream>的区别:
1. .h格式的头文件在98年9月份被标准委员会抛弃.(尽管现在还是大行其道)
2. iostream.h只支持窄字符集,iostream则支持窄/宽字符集。
3. iostream组件全部放入namespace std中,防止了名字污染。
这就是为什么再用#include<iostream>时总要加个using namespace std;的原因.
4. 新标准对iostream作了很多的改动,接口和实现都有了变化。
少了.h却多了更多的内涵.真是简约而不简单啊:)
谢谢
#17
#include <iostream.h>是旧式头文件。
#include <iostream>是标准的 规范的。
#include <iostream>是标准的 规范的。