Original Post
I thought once a default constructor was defined, IT was used whenever creating new instances of the class. However, when the constructor takes no arguments, I do not get this behavior. Consider these situations, where the class MyClass is defined:
The constructor is ALWAYS skipped if i use the parenthesis notation. Even if the constructor is made private (in which case it should give a compile time error when I try to instantiate one), the constructor is skipped. Why is this???
Here is a full source example that shows the problem:
/* Having the empty argument list should be to create this instance (correct me if I''m wrong), however, in this case, the constructor does NOT GET CALLED */ MyClass var1(); /* Instead, I need to write it like this (below) to get it to call the constructor */ MyClass var2; // NO PARENTHESIS
class MyClass
{
public:
MyClass() { cout << "myClass()" << endl; }
};
int main(int argc, char** argv)
{
MyClass myClass1(), myClass2;
// myClass1 will call the constructor (and output 1 line), whereas
// myClass2 will not call the constructor (nothing outputted).
return 0;
}