How to achieve polymorphism

1, polymorphism: The ultimate expression of a variety of forms

2, how to achieve multi-state?

How to implement polymorphism in C yourself? , With a function parameter is a pointer or reference, with the passing of each type of entity, then call their function, which is behind how to call it? Through the virtual function, for each target to establish virtual table vtable, the beginning of the virtual table is a virtual function, and then find their own, so fast speed

                                                                 

Subclasses emergence of new replaced first, then increasing at a corresponding position in the back

Child-parent overloaded, although his father inherited class, but also hidden, so the subclass

Published 128 original articles · won praise 10 · views 10000 +

Guess you like

Origin blog.csdn.net/chanleoo/article/details/104066061