Я создал три класса: Shape
(базовый класс), Rectangle
и Square
. Я пытался вызвать конструктор Shape
из конструкторов Rectangle
и Square
, но компилятор показывает ошибки.
Вот код:
class Shape{
public:
double x;
double y;
Shape(double xx, double yy) {x=xx; y=yy;}
virtual void disply_area(){
cout<<"The area of the shape is: "<<x*y<<endl;
}
};
class Square:public Shape{
public:
Square(double xx){ Shape(xx,xx);}
void disply_area(){
cout<<"The area of the square is: "<<x*x<<endl;
}
};
class Rectnagel:public Shape{
public:
Rectnagel(double xx, double yy){ Shape(xx,yy);}
void disply_area(){
cout<<"The area of the eectnagel is: "<<x*y<<endl;
}
};
int main() {
//create objects
Square sobj(3);
Rectnagel robj(3,4);
sobj.disply_area();
robj.disply_area();
system("pause");;//to pause console screen, remove it if u r in linux
return 0;
}
Есть идеи или предложения по изменению кода?