Suppose I have a class A that does not inherit from anything, has no virtual methods, and has exactly one variable of type T. Does C++ guarantee sizeof(A) == sizeof(T)
?
EDIT:
Also if T were a composite type, would it make a difference?
No, it might be more than sizeof(T)
due to padding.
I don't think it explicitly guarantees it, but I don't think it would ever be different.
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