I do not understand the meaning of the following. This code is (say) a constructor of a class(B) that inherits class(A) and has some other private objects (obj1,obj2 & obj3) derived from class(C). The code is:
1 2 3 4 5 6 7 8 9 10 11 12
class B : public A {
public:
B (double Parm);
protected:
private:
C obj1, obj2, obj3
}
B::B(double Parm):A (tag), obj1(), obj2(), obj3() {
//code
}
What does the inclusion of obj1() etc. in the constructor means?
During the construction of your class, the constructor uses the initialization list to initialize each of the members in the same order they're declared. If no initialization list is defined, all members remain uninitialized, unless assignments are made within the constructor. Note that initialization and assignment are two different terms, but similar.
During the implementation of B's constructor, you're creating an initialization list. Within that list, you're call the constructors of all the C instantiations. The initialization takes place before any statements are executed within the constructor.