Hello again,
I have a question about constructors.
The book I am reading references the "default constructor defined by C++". It says it is not nessecary to define a constructor if this default one is acceptable. Isn't the default constructor just an unitlized/garbage-value oject? or is that not true? Thanks again,
enduser000
The default constructor is a function with the same name as the class that takes no arguements/parameters.
More often than now you may want to use your own constructors that take in parameters. But this is saying that you don't want a constructor, then you don't need to write one. It will implicitly run an empty default constructor for you.
e.g
1 2 3 4
class MyClass {
MyClass() { } // Default Constructor
MyClass(int A) { } // Nth Constructor
};
psault: That'd probably fall in the jurisdiction of the 'coding style'/'standard' they were using at the uni/workplace. But yea, I find it a best practice to code a constructor even if it's empty just to be sure.