Skip to Content
Hands-On Design Patterns with C++
book

Hands-On Design Patterns with C++

by Fedor G. Pikus
January 2019
Intermediate to advanced
512 pages
14h 5m
English
Packt Publishing
Content preview from Hands-On Design Patterns with C++

Type erasure and software design

As we saw in the ill-fated attempt at a fully type-erased sort, type erasure does not always make a program simpler. Even the introduction of standard type-erased classes, such as std::any, does not resolve the fundamental problem—at some point, we need to perform some action on the erased type. At this point, we have two choices—we either need to know the true type, so we can cast to it (using dynamic_cast or any_cast), or we have to operate on the object through a polymorphic interface (virtual functions), which requires that all involved types be derived from the same base class, and constrains the design to the interface of that class. The latter is just regular object-oriented programming, which is, of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Structural Design Patterns in Modern C++

Structural Design Patterns in Modern C++

Umar Lone

Publisher Resources

ISBN: 9781788832564Supplemental Content