3 ms·
My understanding is that, generally (because (again in my understanding) this is all compiler-specific, not mandated by the standard) is that in C++, there's a
by steveklabnik 8y ago
My understanding is that, generally (because (again in my understanding) this is all compiler-specific, not mandated by the standard) is that in C++, there's a single pointer that points to the combo of the vtable and then the data, after it. See http://www.drdobbs.com/cpp/storage-layout-of-polymorphic-objects/240012098 http://www.drdobbs.com/cpp/storage-layout-of-polymorphic-obj... for example. While a Shape is a position, outline, and fill, if you have virtual functions, the pointer points to a vtable pointer, and then all of the data.
In other words, in Rust, a pointer to a shape is
(pointer to vtable, pointer to data)
whereas, in C++, a pointer to a shape is
(pointer to shape)
where shape is
(pointer to vtable, data)
If that's incorrect, I'm quite happy to be corrected! This isn't an area I'm an expert in.
- tzahola 8y agoThat’s absolutely correct. I get it now, that you meant the “pointer to the vtable” under “vtable” in your original post.
- steveklabnik 8y agoAh, I see. Yes, I should probably have been more clear there. Thanks for pointing that out.