Bloomberg LP Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
In addition to default ctor, default copy ctor, default copy assignment operator and destructor, non-const address of (&) and const address of operators would also be generated. (I would imagine the interviewer wanted this answer!)
@michael: sizeof(e) = 1, because C++ differentiates between two objects of same kind.
Everything JeffD mentioned is correct. Also keep in mind that a class Empty {}; differs from a struct EmptyStruct {}; A class generates an entry into the virtual function table (hosted outside of the object). Furthermore, C++ does not allow for allocation of 0 bytes, and sizeof(e) == 1 byte because of this.
Nothing is correct. The class without a virtual declaration will not create a vtable. It also does not have any non-private methods, nor any method body. With that said, it is impossible to reference an object of type Empty. The compiler will ignore this class.
I was thinking 'it's POD; nothing', but, with prompting I guessed the 4 - default ctor, copy ctor, operator=, and dtor.
- JeffD January 29, 2012One twist - later I didn't think it'd even compile, after all being a 'class', the default access is private, and the default ctor should be inaccessible to the public right? Well it turns out that the default ctor is an exception to that, even if there're data and members in the class. The rule does come into effect if you write any of your own ctors (default and otherwise). One more piece of C++ trivia.