For our Sales_data class we’ll define four constructors with the following
parameters:
•An istream& from which to read a transaction.
•A const string&representing an ISBN, an unsigned representing the count
of how many books were sold, and a double representing the price at which
the books sold.
•A const string&representing an ISBN. This constructor will use default
values for the other members. •An empty parameter list (i.e., the default constructor) which as we’ve just seen we must define because we have defined other constructors.
It's legal to have a class without a default constructor. However, if you do that, there are things you won't be able to do with that class, such as use it with various STL containers.
If you don't define any constructors, then the compiler will automatically create an empty default constructor for you. However, if you define any non-default constructor(s), i.e. constructors that take arguments, then the compiler will not create a default constructor.
So, in the example you're discussing, I assume the point is that the writer of the code wants the class to have an empty default constructor, and because there are other constructors defined, the default one has to be explicitly defined.
> there are things you won't be able to do with that class, such as use it with various STL containers.
¿by instance?
I remember `operator[]' of map. But you can have the functionality with `insert()' and `find()'
> So would it be a good practice to always define my own default ones and never rely on the synthesized one?
¿are the ones provided by the compiler not good enough for your?