C++错误:error C2629: unexpected 'class CAR (' 老有问题,求大神帮助 代码:如下
#include<iostream>#include<cmath>usingnamespacestd;#definepi3.1415926classShape{publi...
#include<iostream>
#include<cmath>
using namespace std;
#define pi 3.1415926
class Shape {
public:
virtual double Area()=0;
virtual double Volume()=0;
};
class Circle:public Shape{
public:
Circle(int a){
cout<<"输入圆的半径r:";
r=a;}
double Area(){
return pi*r*r;
}
double Volume(){
return 0;
}
private:
int r;
};
class Rectangle :public Shape{
public:
Rectangle(int w,int l){
cout<<"输入矩形的长与宽";
width=w;length=l;}
double Area(){
return width*length;
}
double Volume(){
return 0;
}
private:
int width;
int length;
};
class CAR {
public:
CAR(shape& s){};
double Area(){return shape.Area();}
double Volume(){return shape.Volume();}
private:
Shape& shape;
};
void main()
{
}
错误提示是:
C:\Documents and Settings\k078\桌面\1111\1111.cpp(43) : error C2629: unexpected 'class CAR ('
C:\Documents and Settings\k078\桌面\1111\1111.cpp(43) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
为什么? 展开
#include<cmath>
using namespace std;
#define pi 3.1415926
class Shape {
public:
virtual double Area()=0;
virtual double Volume()=0;
};
class Circle:public Shape{
public:
Circle(int a){
cout<<"输入圆的半径r:";
r=a;}
double Area(){
return pi*r*r;
}
double Volume(){
return 0;
}
private:
int r;
};
class Rectangle :public Shape{
public:
Rectangle(int w,int l){
cout<<"输入矩形的长与宽";
width=w;length=l;}
double Area(){
return width*length;
}
double Volume(){
return 0;
}
private:
int width;
int length;
};
class CAR {
public:
CAR(shape& s){};
double Area(){return shape.Area();}
double Volume(){return shape.Volume();}
private:
Shape& shape;
};
void main()
{
}
错误提示是:
C:\Documents and Settings\k078\桌面\1111\1111.cpp(43) : error C2629: unexpected 'class CAR ('
C:\Documents and Settings\k078\桌面\1111\1111.cpp(43) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
为什么? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询