GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Jul-2007, 10:35
natasha_u natasha_u is offline
New Member
 
Join Date: Jul 2007
Posts: 1
natasha_u is on a distinguished road

Virtual multiple inheritance: constructors order


Can anyone help me understand how the order of constructors works ina multiple inheritance and some virtual inheritance?
Below some examples

CPP / C++ / C Code:
#include <iostream>
using namespace std;

class A
{
 public: A() {cout << "A ";}
};

class B: virtual public A
{
 public: B() {cout << "B ";}
};

class C: virtual public A
{
 public: C(): A() {cout << "C ";}
};

class D: virtual public B, virtual public C
{
 public: D(): C(), B() {cout << "D ";}
};

/*
class E: public D
{
 public: E(): B() {cout << "E ";}
};
class F: virtual public E 
{
 public: F() {cout << "F ";}
};

//first easy example: prints A B C D E F 
*/

/*
class F: public B, virtual public C 
{
 public: F() {cout << "F ";}
};

//harder one: prints A C B F 
*/

/*
class E: public B
{
 public: E() {cout << "E ";}
};

class F: public E, virtual public C
{
 public: F() {cout << "F ";}
};

//hmmm: prints A C B E F 
*/

class E: virtual public B 
{
 public: E() {cout << "E ";}
};

class F: public E, virtual public C 
{
 public: F() {cout << "F ";}
};
// this one is crazyness: prints A B C E F

main()
{
 F f;
}


HEEEEELP!!!!
Last edited by LuciWiz : 14-Jul-2007 at 11:30. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 17-Jul-2007, 09:27
surya.k surya.k is offline
New Member
 
Join Date: Aug 2006
Posts: 14
surya.k is on a distinguished road

Re: virtual multiple inheritance: constructors order!!


as u have given virtual key word there,it just denies to create duplicate copies in multipath inhritance so, as f is inherited the classes a,b,c,e it calls constructors starting from base class(a) so they printed in that order......
  #3  
Old 25-Jul-2007, 03:26
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 524
Peter_APIIT can only hope to improve

Re: Virtual multiple inheritance: constructors order


What is virtual inheritance ? What virtual inheritance differ from normal public inheritance ?

Thanks for your help.

Your help is greatly appreciated by me and others.
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2 virtual host problem harzu Apache Web Server Forum 12 11-May-2007 15:38
Difference between Virtual and Overloaded Mofix C++ Forum 2 01-Dec-2006 10:35
Help with Virtual Hosting Multiple Websites - Apache 2.2.2 Cheesehead Apache Web Server Forum 1 08-Sep-2006 09:05
Two virtual hosts, cgi script behaves differently on each blimbo Apache Web Server Forum 0 04-Aug-2004 10:35
Can't view pages from another machine on the Intranet aevans Apache Web Server Forum 9 14-May-2004 03:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:51.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.