class call to constructor

This is a discussion on class call to constructor within the C++ Programming forums, part of the General Programming Boards category; What does it mean to modify the class call to constructors, when I have the following situation: class B and ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    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

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    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.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    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 06:37 AM. Reason: accidental premature submission

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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