Sathyaish wrote:
What is a private constructor,
It's a constructor that is declared in a private section of a class.
and why would a class have one?
Because it might not want other classes to be able to create instances of
it.
What are the other kinds of constructors besides:
(1) public constructors; and
(2) parameterized constructors
And I understand that they are not mutually exclusive of one another.
Just like any member, a constructor can be public, protected or private. And
just like normal member functions it can have parameters or not.
There is a special kind of constructors, the conversion constructors. A
constructor that can be called with exactly one argument is considered a
conversion constructor, used to convert the parameter type into the class
the constructor belongs to.
And there is a special kind of conversion constructors, the copy
constructor. It is used to create a copy of an existing object of the same
class. Even though both classes are the same, it counts as a conversion
constructor.