Virtual functions

L

Leon

Hi, I am trying to design a class, which calls all a specific virtual
function from all it's subclasses. Like this:

class Base
{
public:
virtual void theFunction() { // stuff goes here };
};

class firstDerived : public Base
{
public:
virtual void theFunction() { // stuff goes here };
};

class secondDerived : public firstDerived
{
public:
virtual void theFunction() { // stuff goes here };
};

int main()
{
secondDerived* theClass = new secondDerived;
((Base*)secondDerived)->theFunction();
}

Now I want to let the last line (((Base*)secondDerived)->theFunction();)
call all of the theFunction()'s (the base's one, the first derived's one,
and the second derived's one. (without pointers to the
secondDerived::theFunction())

Is this possible?

Leon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top