CppCon 2017: Arthur O'Dwyer “dynamic_cast From Scratch”

CppCon · 27K views · 2017 · 58:49

Open on YouTube

C, C++, Rust, Go & systems languagesCompilers, interpreters & program analysistalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining how virtual calls, typeid and dynamic_cast work under the hood, including the author himself when revisiting an older answer.

Recommended by 0 people across 0 different months, 2018 to 2023.

What it is

A CppCon 2017 talk by Arthur O'Dwyer on the C++ object model, covering vtables, multiple and virtual inheritance, and how dynamic_cast works. It ends by building a complete, fast implementation of dynamic_cast using hand-written RTTI, based on the Itanium C++ ABI.

What people said

Cites Quuxplusone · 2018-06 · Stack Overflow · on “Alternative virtual function calls implementations?”

Well, chalk that up to the state of my knowledge 5 years ago. :) Since then, I've given [this video] and I agree with your assessment. (In my defense, I did say "the equivalent of...", which includes the possibility that the compiler might optimize it, since, again, we're assuming it knows the entire class hierarchy. Also, if you're going to ask "how does this work with DLLs?"... it doesn't. :))

Cites IMAN4K · 2021-06 · Stack Overflow · on “How to know C++ derived class's base class?”

That's the job of the c++ runtime dispatcher to inspect what the most derived type is with the help of typeid Comparison: [LINK] or dynamic_cast conversion: [LINK] also see: [this video]

Cites Marek R · 2023-03 · Stack Overflow · on “What is the purpose of declaring variable templates inline?”

Since link can rotten, copping content of [LINK] here as an answer. I'm not an author. Browser plugin " Copy selection as markdown [LINK] " did nice job. An example where inline constexpr makes a difference [LINK] The C++11 and C++14 standard libraries defined many constexpr global variables like this: constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); constexpr allocator_arg_t allocator_arg = allocator_arg_t(); constexpr error_type error_ctype = /*unspecified*/; constexpr defer_lock_t defer_lock{}; constexpr in_place_t in_place{}; constexpr nullopt_t nullopt(/*unspecified*/{}); In C++17, all of these constexpr variables were respecified as inline constexpr variab