i want to baild an abstract class called: Shape with virtual function "draw"...
a ShapeGroup class will store shapes and draw them !
in ShapeGroup class "DrawAllShapesfunction" we dont know witch shape we are drawing so i use the base class Shape !
but i got a linker error :
unresolved external symbol "public: virtual void __thiscall Shape::draw(void)"
i dont want to set Draw function for base class "Shape", i want to call its deriven classes; witch we dont know their number, name or ...
#include <stdio.h>
class Shape {
public:
virtual void draw();
/*
virtual void draw() {
printf(" Main Shape Draw Function \n");
}
*/
};
class Rectangle: public Shape {
public:
virtual void draw() {
printf("Drawing Shape is Rectangle !\n");
}
};
class Circle : public Shape {
public:
virtual void draw() {
printf("Drawing Shape is Circle !");
}
};
class ShapeGroup {
public:
ShapeGroup() {
shapeCounts = 0;
shapes = new Shape[10];
}
void AddShape(Shape sh) {
shapes[ shapeCounts++ ] = sh;
}
void DrawAllShapes() {
for (int i = 0; i < shapeCounts; i++) {
shapes[i].draw();
}
}
private:
int shapeCounts;
Shape *shapes;
};
int main() {
ShapeGroup *group = new ShapeGroup();
Circle c;
Rectangle r;
group->AddShape(c);
group->AddShape(r);
group->DrawAllShapes();
while (true) {} // so we can see output window...
delete group;
return 0;
}












