Hi.
I have a question about the default constructor.
To my best understanding, the compiler will provide me with a deafult constructor only if there are no any user defined constructors, at all.
now consider the following code:
this code won't compile, since there is "no matching function for call to 'MyClass::MyClass()'".Code:class MyClass { private: int m_data; public: MyClass(int init):m_data(init){cout<<"Ctr called"<<endl;} }; int main() { MyClass obj; }
so far, everything makes sense, since there is no deafult constructor, I can't instantiate a MyClass object without providing one int parameter.
what confusing me is that this code will compile:
Code:class MyClass { private: int m_data; public: MyClass(int init):m_data(init){cout<<"Ctr called"<<endl;} }; int main() { MyClass obj(); //added parentheses }
How is it that suddenly, there is a default constructor?