Reputation: 11231
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++
Upvotes: 0
Views: 127
Reputation:
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.
Upvotes: 2