(I'm sorry, if this was set earlier, the search function seems to be broken: the results pane is completely empty, although it says there are several pages of results ... in Chrome, FireFox and Safari)
So, I'm just learning C ++ ... and the book Im going through does a really bad job of explaining constructors in a way that I can understand them. Ive pretty much left everything else, but I can't figure out how the syntax for constructors works.
For example, I was told that the following would cause the constructor to invoke the assigned constructor of the superclass:
class something : something_else { something(int foo, double bar) : something_else(int foo) {} };
On the other hand, the same syntax was used later in the book when describing the initialization of const members:
class something : something_else { private: const int constant_member; public: something(int foo, double bar) : constant_member(42) {} };
So ... uh ... what the hell is going on there? What rv signature(param) : something_else(what); syntax means rv signature(param) : something_else(what); ? I can’t understand what is something_else(what) , relative to the code around it. It seems to have several meanings; I am sure that there must be some basic element of the language to which it corresponds, I simply cannot understand that.
Edit: Also, I have to mention that it is very confusing that what in the previous example is sometimes a list of parameters (so something_else(what) looks like a function signature) ... and sometimes a constant expression (so something_else(what) looks like function call).
Now, moving on: how about multiple inheritance and constructors? How can I indicate which constructors from which the parent classes are called ... and which of them are called by default? Im aware that by default the following two are the same ... but I'm not sure what the equivalent is when multiple inheritance is involved:
class something : something_else {
Any help finding these topics would be greatly appreciated; I do not like this feeling that Im do not understand something basic. I don’t like it at all.
Edit 2: Good, the answers below are very helpful at the moment. They raise yet another part of this question: How do the arguments of the base constructor-call classes in the "initialization lists" relate to the constructor you define? Do they need to comply ... do they need defaults? How much should they match? In other words, which of the following is illegal:
class something_else { something_else(int foo, double bar = 0.0) {} something_else(double gaz) {} }; class something : something_else { something(int foo, double bar) : something_else(int foo, double bar) {} }; class something : something_else { something(int foo) : something_else(int foo, double bar) {} }; class something : something_else { something(double bar, int foo) : something_else(double gaz) {} };