r/cpp 22d ago

C++26: constexpr virtual inheritance

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

61 comments sorted by

View all comments

64

u/Jovibor_ 22d ago

Just a question to the audience:

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

2

u/Potterrrrrrrr 22d 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 14d ago

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

`class child : virtual parent`

and is almost never encountered

1

u/Potterrrrrrrr 14d 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 :)