Constructor's calls
Mar 15, 2010 at 6:08am UTC
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 Mar 15, 2010 at 6:08am UTC
Mar 15, 2010 at 7:34am UTC
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
Mar 15, 2010 at 7:49am UTC
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 Mar 15, 2010 at 7:49am UTC
Mar 15, 2010 at 1:12pm UTC
Well, extended2 should not be directly calling base's constructor because extended1() is already calling it.
Mar 15, 2010 at 2:38pm UTC
You should think twice about not using a virtual destructor on base.
Topic archived. No new replies allowed.