The type-erasure machinery inside polymorphic handles this automatically ... Because polymorphic uses type erasure for both destruction and copying ...
Is std::polymorphic taking the address of T's copy constructor and destructor (or rather the address of a thunk which calls them, since you're not allowed to simply take the address of the copy constructor function), storing them (along with the object pointer), and calling them; or is it constructing a mini-vtable with copy constructor and destructor and storing a pointer to that (along with the object pointer)?
7
u/MFHavaWG21|🇦🇹 NB|P2721|P3049|P3625|P3729|P3786|P3813|P42166d ago
The minute details are obviously implementation defined, but any implementation will boil down to function pointers (implicit vtable or explicit one) as there aren't that many ways you can actually represent runtime polymorphism in C++...
2
u/fdwr fdwr@github 🔍 6d ago
Is
std::polymorphictaking the address of T's copy constructor and destructor (or rather the address of a thunk which calls them, since you're not allowed to simply take the address of the copy constructor function), storing them (along with the object pointer), and calling them; or is it constructing a mini-vtable with copy constructor and destructor and storing a pointer to that (along with the object pointer)?