Is there a way to make the compiler create the default constructors even if I provide an explicit constructor of my own?
Sometimes I find them very useful, and find it a waste of time to write e.g. the copy constructor, especially for large classes.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The copy constructor is provided whether you define any other constructors or not. As long as you don’t declare a copy constructor, you get one.
The no-arg constructor is only provided if you declare no constructors. So you don’t have a problem unless you want a no-arg constructor, but consider it a waste of time writing one.
IIRC, C++0x has a way of delegating construction to another constructor. I can’t remember the details, but it would allow you to define a no-arg constructor by specifying another constructor, plus the argument(s) to pass to it. Might save typing some data member initializers in some cases. But the default no-arg constructor wouldn’t have provided those initializers either.