HOW CAN I INITIALIZE DATA MEMBERS OF A VIRTUAL CLASS?

Hi everyone, I have a virtual class "Shape.h" and four other classes inheriting from "Shape.h". The other classes are "Circle", "Ellipse", "Square" etc. The program is suppose to draw a shape as an output. The problem i'm having is that the virtual class "Shape.h" holds the properties like pen width, pen color and fill color and I don't know how to initialize the above properties since I can't declare an instance of the class "Shape.h". How can I do this?
Last edited on
You are probably wrong creating objects like Circle circle;.
You need to create pointer to abstract class and then assign pointer to newly created children.

Shape *figure = new Circle;

then you simply type figure-> to access inherited properties.

ps. dont forget to delete figure; after you are done
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Shape{
private:
   length width;
   colour border, fill;
public:
   Shape(length width, colour border, colour fill):
      width(width),
      border(border),
      fill(fill)
   {}
};

class Circle: public Shape{
private:
   length radio;
public:
   Circle(length radio, length width, colour border, colour fill):
      Shape(width, border, fill) //calling the parent constructor
      radio(radio)
   {}
};
Topic archived. No new replies allowed.