Does the C++ standard dictate the compilation layout of the class and struct? How are they compiled differently especially if they are empty?
Does the C++ standard dictate the compilation layout of the class and struct? How
Share
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.
It does in a way, it says that it has to allocate space for it unless certain cases when its used as a base class (known as Empty Base Class Optimization). This is to guarantee that different objects have different addresses.
They are compiled the same given that
structandclassare the same thing, except for the default access specifier. In C++11 the notion of standard-layout classes/structs is introduced, and guarantees that the memory layout for empty classes to be the same.