Thread: class call to constructor

  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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    838
    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

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