代码全对,为什么编译出错?
Point.h文件:# ifndef POINT_H
# define POINT_H
class Point{
int x,y;
public:
Point(int a,int b);
void SetPoint(int a,int b);
int GetX();
int GetY();
void Print();
}
# endif
Circle.h文件
# ifndef CIRCLE_E
# define CIRCLE_E
# include<iostream>
using namespace std;
# include"Point.h"
class Circle:public Point{
double radius;
public:
Circle(int a,int b, double r);
void SetRadius(double r);
double GetRadius();
double Area();
void Print();
};
# endif
Point.cpp文件
# include<iostream>
using namespace std;
# include"Point.h"
Point::Point(int a,int b){
Point::SetPoint(a,b);
}
void Point::SetPoint(int a,int b){
Point::x=a;
Point::y=b;
}
void Point::Print(){
cout<<"["<<x<<","<<y<<"]";
}
Circle.cpp文件
# include<iostream>
# include"Circle.h"
using namespace std;
Circle::Circle(int a,int b,double r):Point(a,b){
Circle::SetRadius(r);
}
void Circle::SetRadius(double r){
radius=(r>=0 ? r:0);
}
double Circle::GetRadius(){
return radius;
}
double Circle::Area(){
return 3.14159*radius*radius;
}
void Circle::Print(){
cout<<"Center = ";
Point::Print();
cout<<";Radius = "<<radius<<endl;
}
CircleDemo.cpp文件
# include<iostream>
# include"Circle.h"
using namespace std;
Circle::Circle(int a,int b,double r):Point(a,b){
Circle::SetRadius(r);
}
void Circle::SetRadius(double r){
radius=(r>=0 ? r:0);
}
double Circle::GetRadius(){
return radius;
}
double Circle::Area(){
return 3.14159*radius*radius;
}
void Circle::Print(){
cout<<"Center = ";
Point::Print();
cout<<";Radius = "<<radius<<endl;
}
在编译的时候出现了如下错误:
--------------------Configuration: PointCircle - Win32 Debug--------------------
Compiling...
CircleDemo.cpp
f:\vc++\vc++程序\myobject\pointcircle\circle.h(4) : error C2143: syntax error : missing ';' before 'using'
F:\vc++\vc++程序\MyObject\PointCircle\CircleDemo.cpp(8) : error C2661: 'Circle::Circle' : no overloaded function takes 4 parameters
执行 cl.exe 时出错.
CircleDemo.obj - 1 error(s), 0 warning(s)
这是我从课本上写下来的,怎么会这样呢?