Say I have a class. I want it to have a constructor that takes certain arguments, so I make one. Do I still need to have a constructor that has no arguments (default constructor) even if I don't need it? In other words, do i have to include Class()
as a member function even if I don't need it?
No, if you don't need it then you don't need it.
You only need it if you want to be able to default-initialise the class. Often you don't want that - you only want objects to exist if they were correctly initialised with the constructor(s) you wrote - which is why declaring your own constructor removes the implicit default constructor.
No. Make a class that does what you need, not one that adheres to cargo cults for no reason. Rubber duck the class if in doubt.
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