what ALL gets created by an empty class? (c++)
-
Hey there - what happens when someone creates a class: class empty{ }; I know there are the four member functions that would be created - constructor, destructor, assignment and copy. but what else? I was asked this in an interview and confidently replied with the four functions above - only to be told that really knowledgable C++ folks would be able to name anywhere between 6 - 9 things. Any other answers out there? I've looked online and in all my c++ books. Thanks!
-
Hey there - what happens when someone creates a class: class empty{ }; I know there are the four member functions that would be created - constructor, destructor, assignment and copy. but what else? I was asked this in an interview and confidently replied with the four functions above - only to be told that really knowledgable C++ folks would be able to name anywhere between 6 - 9 things. Any other answers out there? I've looked online and in all my c++ books. Thanks!
dd314159 wrote:
Any other answers out there?
The compiler might also create address-of operators. That said, these (five) items don't always get created, only when they are needed.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hey there - what happens when someone creates a class: class empty{ }; I know there are the four member functions that would be created - constructor, destructor, assignment and copy. but what else? I was asked this in an interview and confidently replied with the four functions above - only to be told that really knowledgable C++ folks would be able to name anywhere between 6 - 9 things. Any other answers out there? I've looked online and in all my c++ books. Thanks!
dd314159 wrote:
I know there are the four member functions that would be created - constructor, destructor, assignment and copy. but what else?
Not always. For instance, the compiler will provide constructor only if there are some virtual functions(to prepare vtable), or if any of the member variables have constructors. I strongly recommend you to read the book "Inside C++ Object Model". http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545[^] Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
dd314159 wrote:
I know there are the four member functions that would be created - constructor, destructor, assignment and copy. but what else?
Not always. For instance, the compiler will provide constructor only if there are some virtual functions(to prepare vtable), or if any of the member variables have constructors. I strongly recommend you to read the book "Inside C++ Object Model". http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545[^] Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
dd314159 wrote:
Any other answers out there?
The compiler might also create address-of operators. That said, these (five) items don't always get created, only when they are needed.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne