polymorphism - Dynamic instantiation in C++ -
I want my code to be extensible, in this way I can create objects in sequence.
For example, suppose I have a grocery class in which there is an array of fruit and I want to fill this crop with fruit which is obtained from the fruit.
class fruit {}; Class grocery {std :: vector & lt; Fruit * & gt; M_fruits; }; Square apple: fruit {}; Class pineapple: fruit {}; Now on the runtime, I want my grocery square vector m_fruits
to fill it with classical items of Apple and pineapple. So is it possible in some way? If I add another fruit in the form of strawberries in the future, then its object and the implementation of the grocery category will be added to the grocery vector at no pace?
Code support will be appreciated.
Check your textbook It is mentioned that you only indicators Types can be treated polymorphically In other words, a vector of indicators for the fruit can take indicators apples or pineapple.
Comments
Post a Comment