求教,新手入门有关问题
求教,新手入门问题
我本身是机械专业的,最近在自学c++,找的教程是清华大学出版社的《c++语言程序设计(第二版)》,以前找过《c++ primer》来大概看了下,觉得用来入门似乎深了,所以就看现在的这本书,今天看到类的组合书里面有道例题,总是不能通过编译(例题在后面,是求两点的距离,是距离类和点类的组合),所以想在这里请教下面的问题:
1.我用的IDE是dev-c++,在编译的时候总有一个错误通不过,信息显示拷贝如下
32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #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.
40 C:\Documents and Settings\Administrator\My Documents\2point.cpp `main ' must return `int '
这到底是32行的头文件问题还是40行的main返回值必须是int的问题,谁能帮我解释下吗?
2.main的返回值必须是int这句怎么解释啊,难道说main函数使用其他数据类型必须在main中单独声明?
3.还有就是关于using namespace std;,在我使用的书里面推荐用 vc6.0我嫌那东西太大没装,就用的devc++,结果书上有的例题有编译不过去,我在搜索的到的结果是命名空间的问题,我想知道在那里能找到关于这部分的详细资料和说明?
#include <iostream.h>
#include <math.h>
using namespace std;
class Point //point类声明
{
public:
Point(int xx=0,int yy=0) {X=xx;Y=yy;}
Point(Point &p);
int GetX() {return X;}
int GetY() {return Y;}
private:
int X,Y;
};
Point::Point(Point &p) //拷贝构造函数的实现
{
X = p.X;
Y = p.Y;
cout < < "Point拷贝构造函数被调用 " < < endl;
}
//类的组合
class Distance //Distance类的声明
{
public:
Distance(Point xp1,Point xp2);
double GetDis(){return dist;}
private:
Point p1,p2;
double dist;
};
//组合类的构造函数
Distance::Distance(Point xp1,Point xp2):p1(xp1),p2(xp2)
{
cout < < "Distance构造函数被调用 " < < endl;
double x = double(p1.GetX() - p2.GetX());
double y = double(p1.GetY() - p2.GetY());
dist = sqrt(x * x + y * y);
}
//主函数
void main()
{
Point myp1(1,1),myp2(4,5);
Distance myd(myp1,myp2);
cout < < "The distance is: " < < endl;
cout < < myd.GetDis() < < endl;
}
------解决方案--------------------
我本身是机械专业的,最近在自学c++,找的教程是清华大学出版社的《c++语言程序设计(第二版)》,以前找过《c++ primer》来大概看了下,觉得用来入门似乎深了,所以就看现在的这本书,今天看到类的组合书里面有道例题,总是不能通过编译(例题在后面,是求两点的距离,是距离类和点类的组合),所以想在这里请教下面的问题:
1.我用的IDE是dev-c++,在编译的时候总有一个错误通不过,信息显示拷贝如下
32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #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.
40 C:\Documents and Settings\Administrator\My Documents\2point.cpp `main ' must return `int '
这到底是32行的头文件问题还是40行的main返回值必须是int的问题,谁能帮我解释下吗?
2.main的返回值必须是int这句怎么解释啊,难道说main函数使用其他数据类型必须在main中单独声明?
3.还有就是关于using namespace std;,在我使用的书里面推荐用 vc6.0我嫌那东西太大没装,就用的devc++,结果书上有的例题有编译不过去,我在搜索的到的结果是命名空间的问题,我想知道在那里能找到关于这部分的详细资料和说明?
#include <iostream.h>
#include <math.h>
using namespace std;
class Point //point类声明
{
public:
Point(int xx=0,int yy=0) {X=xx;Y=yy;}
Point(Point &p);
int GetX() {return X;}
int GetY() {return Y;}
private:
int X,Y;
};
Point::Point(Point &p) //拷贝构造函数的实现
{
X = p.X;
Y = p.Y;
cout < < "Point拷贝构造函数被调用 " < < endl;
}
//类的组合
class Distance //Distance类的声明
{
public:
Distance(Point xp1,Point xp2);
double GetDis(){return dist;}
private:
Point p1,p2;
double dist;
};
//组合类的构造函数
Distance::Distance(Point xp1,Point xp2):p1(xp1),p2(xp2)
{
cout < < "Distance构造函数被调用 " < < endl;
double x = double(p1.GetX() - p2.GetX());
double y = double(p1.GetY() - p2.GetY());
dist = sqrt(x * x + y * y);
}
//主函数
void main()
{
Point myp1(1,1),myp2(4,5);
Distance myd(myp1,myp2);
cout < < "The distance is: " < < endl;
cout < < myd.GetDis() < < endl;
}
------解决方案--------------------