So I know that after you write a constructor in a class the default constructor goes away, so you have to start initializing every object. However, is there a way to write a default constructor so that you don't have to do this?
Thanks.
Before C++11
class MyClass
{
public:
MyClass(int x, int y) {}
MyClass() {}
};
or in C++11
class MyClass
{
public:
MyClass(int x, int y) {}
MyClass() = default;
};
You can write as many constructors as you like, but avoid making your class confusing to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With