Virtual Functions

Started by
10 comments, last by braves 23 years, 7 months ago
I think I understand now!!!!!!!!!
Ok, so with an abstract class you can''t do this :
class Shape
{
public:
virtual void Create() = 0;
virtual void Draw() = 0;
virtual void Print() = 0;
};

class Square : public Shape
{
public:
virtual void Create();
virtual void Draw();
virtual void Print();
};

class Circle : public Shape
{
public:
virtual void Create();
virtual void Draw();
virtual void Print();
};

class Triangle : public Shape
{
public:
virtual void Create();
virtual void Draw();
virtual void Print();
};


void main
{
Shape *myarray[4];

Shape *myshape = new Shape; <== can''t do
Shape *mysquare = new Square;
Shape *mycircle = new Circle;
Shape *mytriangle = new Triangle;

myarray[0] = myshape; <== can''t do
myarray[1] = mysquare;
myarray[2] = mycircle;
myarray[3] = mytriangle

The mistake I was making before when people said with an abstract class, you could not declare an instance of it...I thought they were talking about this

Shape *myarray[4]; Instance as in creating the object.
Howerver, I know that is not the case now.
Thank you every for your help!
Braves




Advertisement
Yep, you got it. Glad to be of service =)
- Houdini

This topic is closed to new replies.

Advertisement