In single inheritances, is the size of a pointer to virtual table always equal to the size of a void*? Say,
class vft { virtual ~vft(); }
assert (sizeof(vft) == sizeof(void*));
Would that assertion always be true?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The C++ ISO Standard says nothing about virtual function table pointer in the first place. A Compiler may follow this mechanism to support runtime-polymorphism or can come up with any other which doesn’t even involve
vptr. Its entirely upto the compiler writers. Since the Standard doesn’t say anything aboutvptr, how can it say about its size? No way. The conclusion is: what you’re doing (or assuming) isn’t gauranteed by the language. However, for a compiler, it might be always true.As a sidenote, for your compiler, how can you conclude that
sizeof(vft)will be equal tosizeof(vptr)? It could very well be thatsizeof(vft) > sizeof(vptr). I don’t claim that though.