- Examples
Explore C++ design examples illustrating type erasure using both object-oriented programming and template techniques. Understand the advantages and drawbacks of each method, including virtual dispatch and template flexibility. This lesson helps you grasp how to implement polymorphism efficiently with clean design.
We'll cover the following...
We'll cover the following...
Example 1: Type Erasure Using Object-Oriented Programming
Explanation
The key point is that you can use instances of Foo or Bar instead of an instance for BaseClass. std::vector<BaseClass*> (line 35) has a pointer to BaseClass. Well, actually it has two pointers to BaseClass (derived) objects and it is a vector of such ...