C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-03-2009, 03:28 PM   #1
Registered User
 
Join Date: Jan 2008
Posts: 540
class call to constructor

What does it mean to modify the class call to constructors, when I have the following situation:

class B and C inherits from A, class D inherit from B and C. A has a variable that is declared as public called count.

D calls the non-default constructor of it's of the ancestor
-EquinoX- is online now   Reply With Quote
Old 11-03-2009, 03:44 PM   #2
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by -EquinoX- View Post
What does it mean to modify the class call to constructors, when I have the following situation:

class B and C inherits from A, class D inherit from B and C. A has a variable that is declared as public called count.

D calls the non-default constructor of it's of the ancestor
Well, since that's a diamond inheritance, the base A object will be double-constructed unless you specify the inheritance as virtual. Beyond that I don't know what you mean.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 11-04-2009, 07:31 AM   #3
3735928559
 
Join Date: Mar 2008
Posts: 662
it means that D passes an argument in its constructor calls to its ancestors.

e.g:

Code:
class A
{
  public:
  int count;
  A():count(0){} // <- default constructor (no arguments passed)
  A(int _count):count(_count){} // <- non default constructor
};

class B : public A
{
  B():A(){}
  B(int _count):A(_count){}
};

class C : public A
{
  C():A(){}
  C(int _count):A(_count){}
};

class D : public B,public C
{
  public:
  D(): B(1), C(2) {}
}

Last edited by m37h0d; 11-04-2009 at 07:37 AM. Reason: accidental premature submission
m37h0d is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
temperature sensors danko C Programming 22 07-10-2007 07:26 PM
Class won't call Aalmaron C++ Programming 3 04-13-2006 04:57 PM
Having a class function call a function outside the class Aeroren C++ Programming 2 08-09-2005 06:33 AM
My Window Class Epo Game Programming 2 07-10-2005 02:33 PM
gcc problem bjdea1 Linux Programming 13 04-29-2002 06:51 PM


All times are GMT -6. The time now is 01:57 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22