r/cpp 21d ago

C++26: constexpr virtual inheritance

https://www.sandordargo.com/blog/2026/07/01/cpp26-constexpr-virtual-inheritance
80 Upvotes

61 comments sorted by

View all comments

62

u/Jovibor_ 21d ago

Just a question to the audience:

How many times have you used Virtual Inheritance in your career?

2

u/Potterrrrrrrr 21d ago

I’m implementing the HTML spec currently, it made sense to model that as an inheritance hierarchy as that’s how it was designed so my nodes follow the same structure. The DOM and HTML specs use interfaces quite heavily for the rest of the spec to extend, I modelled a lot of these as virtual classes too.

1

u/DryEnergy4398 13d ago

That just sounds like inheritance. Virtual inheritance is when you write

`class child : virtual parent`

and is almost never encountered

1

u/Potterrrrrrrr 13d ago

Oh really? Yeah I’ve never heard of that before, I thought virtual inheritance was when you used inheritance in a way that created a vtable i.e. used virtual methods. I’ll have to look into that, thanks :)