Idioms and Patterns: Type Erasure
In this lesson, we'll learn about type erasure in detail.
We'll cover the following...
We'll cover the following...
Type Erasure
Type Erasure enables you to use various concrete types through a single generic interface.
Type erasure is duck typing applied in C++
“When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.” (James Whitcomb Rileys)
Of course, you’ve already used type erasure in C++ or C. The C-ish way of type erasure is a void
pointer; the C++ish way of type erasure is object-orientation.
Typical Use Case
Type erasure can be performed with void
pointers, object-orientation, or templates. ...