Hmmmm This doesn't seems to be what I'm trying to do. I need the child class to do more than print, I need it to print in a specific way.
can child class can inherit from 2 parent classes?
It seems you have decided to implement things a different way, but in my example each child class would be responsible for defining the specific way that class should print. The ArtRenderer class only defines the functions the child classes are required to implement (in this case, the show() method). The specifics of how each child class implements the show method is not restricted in any way. One class could render things as ASCII art, and the other through OpenGL. But, after reading through your additional posts, inheritance isn't really needed to solve your problem.
@SeanMiddleditch
Aggregation is fine until you have lots of different classes that all have to implement a show function. In your example, with aggregation alone you would have:
class A {
public:
void render();
};
class B {
public:
void render();
};
class C {
public:
void render();
};
class C {
public:
void render();
};
class D {
public:
void render();
};
class E {
public:
void render();
};
class F {
A* a;
B* b;
C* c;
D* d;
E* e;
// and so on
public:
void render() {
a->render();
b->render();
c->render();
d->render();
e->render();
// and so on
}
};
It's pretty concise if anything that can be rendered implements a Renderable interface. Then anytime you need to hold several Renderable objects, you can just refer to them through the interface type. For example, you can then store all of your Renderable objects in a data structure (e.g. maybe you want to keep things in a tree to optimize collision detection) - which essentially aggregates all of the objects. Saves you from having to deal with the ugliness of templates.
Regardless, can you post some links to data-driven programming tutorials? It's useful stuff to know about.