[问题]在VISUAL C++下通过的,在ANJUTA IDE无法通过?(已解决)

软件和网站开发以及相关技术探讨
回复
wangdong2089
帖子: 18
注册时间: 2007-11-10 20:56

[问题]在VISUAL C++下通过的,在ANJUTA IDE无法通过?(已解决)

#1

帖子 wangdong2089 » 2007-11-30 19:20

#include<iostream.h>
class complex //复数类声明
{
public: //外部接口
complex(double r=0.0,double i=0.0){real=r;imag=i;} //构造函数
friend complex operator + (complex c1,complex c2); //运算符+重载友元函数
friend complex operator - (complex c1,complex c2); //运算符-重载友元函数
void display(); //显示复数的值
private: //私有数据成员
double real;
double imag;
}; //显示函数实现
void complex::display()
{ cout<<"("<<real<<","<<imag<<")"<<endl;}
complex operator +(complex c1,complex c2) //运算符重载友元函数实现
{ return complex(c2.real+c1.real,c2.imag+c1.imag);}
complex operator -(complex c1,complex c2) //运算符重载友元函数实现
{ return complex(c1.real-c2.real,c1.imag-c2.imag);}
void main() //主函数
{
complex c1(5,4),c2(2,10),c3;
cout<<"c1=";c1.display();
cout<<"c2=";c2.display();
c3=c1-c2; //使用重载运算符
cout<<"c3=c1-c2=";
c3.display();
c3=c1+c2; //使用重载运算符
cout<<"c3=c1+c2=";
c3.display();
}

make
make all-recursive
make[1]: Entering directory `/home/david/Projects/lei2'
Making all in src
make[2]: Entering directory `/home/david/Projects/lei2/src'
g++ -DHAVE_CONFIG_H -I. -I. -I.. -DPACKAGE_LOCALE_DIR=\""/usr/local//locale"\" -DPACKAGE_SRC_DIR=\""."\" -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -g -O2 -MT main.o -MD -MP -MF ".deps/main.Tpo" -c -o main.o main.cc
在包含自 /usr/include/c++/4.1.3/backward/iostream.h:31 的文件中,
从 main.cc:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: 警告: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/home/david/Projects/lei2/src/main.cc:19: 错误: ‘::main’ 必须返回 ‘int’
make[2]: *** [main.o] 错误 1
make[2]: Leaving directory `/home/david/Projects/lei2/src'
make[1]: *** [all-recursive] 错误 1
make: *** [all] 错误 2
make[1]: Leaving directory `/home/david/Projects/lei2'
Completed... unsuccessful
总共耗时:3 秒
上次由 wangdong2089 在 2007-11-30 21:33,总共编辑 1 次。
头像
tipfoo
帖子: 303
注册时间: 2007-07-12 16:30
来自: 桂林

#2

帖子 tipfoo » 2007-11-30 20:24

很明显啊,编译器都告诉你了,要将这一行

代码: 全选

void main() //主函数 
改成

代码: 全选

int main() //主函数 
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

#3

帖子 dbzhang800 » 2007-11-30 20:32

楼主还是先找本新一点的符合标准的C++的书看看吧。
wangdong2089
帖子: 18
注册时间: 2007-11-10 20:56

#4

帖子 wangdong2089 » 2007-11-30 21:31

我这个学期才学C++,一开始学就用了旧书,悲哀!
回复