本人新手,下面的代码编译时为什么出现有关问题,多谢
本人新手,下面的代码编译时为什么出现问题,谢谢
#include<iostream>
using namespace std;
class Point
{
public:
Point(float x,float y)
{
X=x;
Y=y;
}
protected:
float X,Y;
};
class Rectangle:public Point
{
public:
Rectangle(float x,float y,float l,float w);
protected:
float L,W;
};
class Cube:public Rectangle
{
Cube(float x,float y,float z,float l,float w,float h);
protected:
float Z,H;
};
Rectangle::Rectangle(float x,float y,float l,float w):Point(x,y)
{
L=l;
W=w;
}
Cube::Cube(float x,float y,float z,float l,float w,float h):Rectangle(x,y,l,w)
{
Z=z;
H=h;
}
int main()
{
Cube c(2,3,4,5,6,7);
return 0;
}
------解决方案--------------------
#include<iostream>
using namespace std;
class Point
{
public:
Point(float x,float y)
{
X=x;
Y=y;
}
protected:
float X,Y;
};
class Rectangle:public Point
{
public:
Rectangle(float x,float y,float l,float w);
protected:
float L,W;
};
class Cube:public Rectangle
{
Cube(float x,float y,float z,float l,float w,float h);
protected:
float Z,H;
};
Rectangle::Rectangle(float x,float y,float l,float w):Point(x,y)
{
L=l;
W=w;
}
Cube::Cube(float x,float y,float z,float l,float w,float h):Rectangle(x,y,l,w)
{
Z=z;
H=h;
}
int main()
{
Cube c(2,3,4,5,6,7);
return 0;
}
------解决方案--------------------
class Cube:public Rectangle
{
public: //构造函数要为public
Cube(float x,float y,float z,float l,float w,float h);