Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ sizeof wrapper class

Tags:

c++

class

sizeof

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?

like image 698
Thomas Eding Avatar asked May 13 '11 15:05

Thomas Eding


2 Answers

No, it might be more than sizeof(T) due to padding.

like image 186
Naveen Avatar answered Oct 12 '22 18:10

Naveen


I don't think it explicitly guarantees it, but I don't think it would ever be different.

like image 25
Seth Carnegie Avatar answered Oct 12 '22 20:10

Seth Carnegie