Private Classes included in Class Constructor decleration

Sep 2, 2011 at 9:04am
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?

Thanks in advance!
Sep 2, 2011 at 10:12am
Sep 2, 2011 at 5:47pm
closed account (zb0S216C)
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.

Wazzak
Last edited on Sep 2, 2011 at 11:40pm
Topic archived. No new replies allowed.