I have a general question, that may be a little compiler-specific. I'm interested in the conditions under which a constructor will be called. Specifically, in release mode/builds optimised for speed, will a compiler-generated or empty constructor always be called when you instantiate an object?
class NoConstructor
{
int member;
};
class EmptyConstructor
{
int member;
};
class InitConstructor
{
InitConstructor()
: member(3)
{}
int member;
};
int main(int argc, _TCHAR* argv[])
{
NoConstructor* nc = new NoConstructor(); //will this call the generated constructor?
EmptyConstructor* ec = new EmptyConstructor(); //will this call the empty constructor?
InitConstructor* ic = new InitConstructor(); //this will call the defined constructor
EmptyConstructor* ecArray = new EmptyConstructor[100]; //is this any different?
}
I've done a lot of searching, and spent some time looking through the generated assembly code in Visual Studio. It can be difficult to follow in release builds though.
In summary: Is the constructor always called? If so, why?
I understand this will very much depend on the compiler, but surely there's a common stance. Any examples/sources you can cite would be really appreciated.