[Error] 'a' was not declared in this scope
[Error] 'b' was not declared in this scope
每个构造函数都这样报错
#include <iostream>
using namespace std;
class Container{
protected:
double s,v,h;
public:
virtual void out(){
cout<<"s="<<s<<"v="<<s*h;
}
Container(double a,double b){
s=a;
h=b;
v=s*h;
}
};
class Sphere:public Container{
private:
double r;
public:
virtual void out(){
s=4*3.1415926*r*r;
v=s*r/3;
cout<<"s="<<s<<"v="<<v;
}
Sphere(double i):Container(a,b){
r=i;
}
};
class Cylinder:public Container{
private:
double r;
public:
virtual void out(){
s=2*3.1415926*r*r+2*3.1415926*r*h;
v=h*3.1415926*r*r;
cout<<"s="<<s<<"v="<<v;
}
Cylinder(double m):Container(a,b){
r=m;
}
};
class Cube:public Container{
private:
double l;
public:
virtual void out(){
s=6*l*l;
v=l*l*l;
cout<<"s="<<s<<"v="<<v;
}
Cube(double n):Container(a,b){
l=n;
}
};
int main() {
return 0;
}
题目:写一个程序,定义抽象基类Container,由它派生出3个派生类Sphere(球体)、Cylinder(圆柱体)、Cube(正方体)。用虚函数分别计算几种图形的表面积和体积。