Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Duck Typing, the C++ Way - How Type Erasure Bends the Rules

CppCon via YouTube

Overview

Coursera Flash Sale
40% Off Coursera Plus for 3 Months!
Grab it
Explore type erasure as one of C++'s most powerful yet underrated idioms in this 56-minute conference talk from CppCon 2025. Discover how type erasure enables runtime polymorphism without inheritance while maintaining C++'s static safety guarantees, drawing parallels to duck typing found in dynamic languages. Learn how the C++ Standard Library leverages type erasure in essential tools like std::function and std::shared_ptr to store, dispatch, and manage heterogeneous objects with minimal friction. Build understanding through hands-on exploration as you examine a simplified version of std::function crafted from scratch and investigate how std::shared_ptr uses type erasure to maintain type safety while enabling polymorphic deletion. Uncover the hidden performance costs, memory allocations, and vtable machinery that accompany type-erased constructs through profiling and real-world scenarios. Evaluate when type erasure justifies its trade-offs versus alternatives like templates or CRTP (Curiously Recurring Template Pattern). Gain practical intuition for wielding type erasure judiciously to write cleaner, more flexible, and performance-aware modern C++ code while understanding its inner workings and appropriate use cases.

Syllabus

Duck Typing, the C++ Way: How Type Erasure Bends the Rules - Sarthak Sehgal - CppCon 2025

Taught by

CppCon

Reviews

Start your review of Duck Typing, the C++ Way - How Type Erasure Bends the Rules

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.