C++ has virtual functions, where invoking one will at runtime look up the function address in a vtable.
C++ also has virtual bases. Accessing a data member of a virtual base will at runtime look up the offset the vtable.
Why does C++ lack virtual data members? Accessing one would look up the offset in the vtable as for a virtual base, but the data member would be provided by a derived
virtual void fun();
virtual int val;
void fun() override;
int val override;
Your talk of offsets is an implementation detail.
The content of a virtual function can change in derived instances.
The content of a non-virtual data member can change in derived instances.
A shared data member in the diamond inheritance sense can be implemented via virtual inheritance.
A polymorphic member can be implemented with a virtual accessor.
At best this is syntactic sugar, and not very much of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With