c++ is a wonderful language with a lot of flexibility and a lot of power. It’s also a terrible language for coding. The best way to learn and use c++ is to use it. However, there are some cases when you can’t use it. Those are the times you have to learn and use it the way you would do it in c# or java.
C++ is the language of c++, therefore we can say that c++ multiple constructors is one of those “cases” where the language does not support multiple constructors and you can’t use the language to its full potential.
c++ multiple constructors is an attempt to solve this problem by extending all the c++ constructs to allow for constructors with different number of arguments. In c++, the default constructors have 2 arguments and the other constructors have 3 arguments. This allows you to have a constructor that takes just one argument and another constructor that takes two separate arguments. It’s like getting rid of the default and giving each constructor a different name and using each constructor to its full potential.
There’s a lot more to this that you should probably know about constructors, so I’ll just say this much: They’re a huge, huge part of the c language. They are an integral part of the c language and its c programming model. They’re used in so many places that it’s easy to forget how big a deal they can be.
A constructor is a statement that defines what the variable in question is. This statement is made in the context of the constructor body and is available throughout the constructor (and outside of it too). They are also used for allocating the variables within a function and to pass variables to functions. Some C implementations use them in the same way as variables for this reason.
In C++, constructors are called constructors. There are two kinds, depending on whether they create an object or initialize an instance of an object. A constructor that creates an object is called a constructor with a default constructor, and constructors that return an object are called constructor templates.
While it’s perfectly fine to allocate a variable that is not initialized when a constructor is called, I’m inclined to consider that a bug. If I’m not careful, I may end up with a variable that is not initialized. In my testing, this seems to happen on a very small number of occasions and is extremely seldom actually the case.
A similar problem exists in C#. If an object needs to be made of more than one type (like a string, or a string array), I have had to do so with a loop. In both languages, most of the time the loop is declared early in the method so that it is not needed in the constructor. In C#, this causes a problem because if I declare the constructor inside the loop, I have to change the code so that it is called from the constructor.
This is a problem because it is very hard to see how a loop could be used to make a constructor of an object a loop.