Constructor's calls



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class base
{
base()   {}
~base() {}
};



class extended1 : public base
{
public:
extended1():base()    {}
~ extended1()        {}
};



Class extended2 : public extended1
{
Public:
extended2() : base(),extended1()    {}
~extended2()   {}
};



is there anything wrong on creating object of extended2 class, other than extra calls to base constructor.
Last edited on
Possibly - As you have written it:
class base constructor is private

class base is not a direct base class of class extended2 - so it connot be in the initialization list.

Class extended2 : public extended1 error - should be class extended2 : public extended1
oh.. the code was

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class base
{
public:
base()   {}
~base() {}
};



class extended1 : public base
{
public:
extended1():base()    {}
~ extended1()        {}
};



class extended2 : public extended1
{
public:
extended2() : base(),extended1()    {}
~extended2()   {}
};


Last edited on
Well, extended2 should not be directly calling base's constructor because extended1() is already calling it.
You should think twice about not using a virtual destructor on base.
Topic archived. No new replies allowed.