tags:

views:

54

answers:

1

Lets say I have a Base class as Parent and I want to know how many classes are derived from this class at runtime and create objects of all those classes along with calling the pure virtual function I declared in my Parent class.

How to do this in c++

+2  A: 

I can't see why you would want to do it, and in fact it is not possible under all circumstances - you will need to instantiate all the classes you are counting. One approach is for each derived class will need a static member indicating if it has informed the base class that it is derived - this gets called from the derived class's constructor, but only once per derived class. The base then keeps a static counter of the number of times it has been so informed.

anon
If you need to do this, you probably don't understand OO
Joel