Click here to Skip to main content
15,881,139 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: OLE Object From Clipboard Data Pin
Matthew Faithfull13-Mar-08 22:49
Matthew Faithfull13-Mar-08 22:49 
QuestionHow to set the variables to the computer time? Pin
cshong13-Mar-08 17:02
cshong13-Mar-08 17:02 
AnswerRe: How to set the variables to the computer time? Pin
Naveen13-Mar-08 17:40
Naveen13-Mar-08 17:40 
GeneralRe: How to set the variables to the computer time? Pin
cshong14-Mar-08 4:20
cshong14-Mar-08 4:20 
GeneralRe: How to set the variables to the computer time? Pin
Naveen16-Mar-08 14:10
Naveen16-Mar-08 14:10 
QuestionHow to block another program internet access? Pin
StarMeteor13-Mar-08 16:26
StarMeteor13-Mar-08 16:26 
GeneralRe: How to block another program internet access? Pin
Rajkumar R13-Mar-08 21:35
Rajkumar R13-Mar-08 21:35 
GeneralVirtual base class Pin
George_George13-Mar-08 16:06
George_George13-Mar-08 16:06 
Hello everyone,


Here is the related C++ Spec and my test code. I think virtual base class, no matter direct virtual base class or not, will always be constructed before non-virtual class (including non-virtual direct base class), correct?

Another question is, what means "and only for the constructor of the most derived class as described below" in related Spec statements?

Spec:

--------------------
12.6.2 Initializing bases and members [class.base.init]

5 Initialization shall proceed in the following order:
— First, and only for the constructor of the most derived class as described below, virtual base classes shall
be initialized in the order they appear on a depth-first left-to-right traversal of the directed acyclic graph
of base classes, where “left-to-right” is the order of appearance of the base class names in the derived
class base-specifier-list.
— Then, direct base classes shall be initialized in declaration order as they appear in the base-specifier-list
(regardless of the order of the mem-initializers).
— Then, nonstatic data members shall be initialized in the order they were declared in the class definition
(again regardless of the order of the mem-initializers).
— Finally, the body of the constructor is executed.
[Note: the declaration order is mandated to ensure that base and member subobjects are destroyed in the
reverse order of initialization. ]
--------------------

/*
output
constructor B1
constructor B2
constructor D2
constructor D1
constructor D3
*/

#include <iostream>

using namespace std;

class B1 {
public:
	 B1()
	 {
		 cout << "constructor B1 " << endl;
	 }
};

class B2 {
public:
	 B2()
	 {
		 cout << "constructor B2 " << endl;
	 }
};

class D1 : virtual public B1 {
public:
	 D1()
	 {
		 cout << "constructor D1 " << endl;
	 }
};

class D2 : public virtual B1, public B2 {
public:
	 D2()
	 {
		 cout << "constructor D2 " << endl;
	 }
};

class D3 : public D1, virtual public D2 {
public:
	 D3()
	 {
		 cout << "constructor D3 " << endl;
	 }
};

int main()
{
	D3 d;
	return 0;
}



thanks in advance,
George
GeneralRe: Virtual base class Pin
Eytukan13-Mar-08 16:25
Eytukan13-Mar-08 16:25 
GeneralRe: Virtual base class Pin
George_George13-Mar-08 16:34
George_George13-Mar-08 16:34 
GeneralRe: Virtual base class Pin
ThatsAlok13-Mar-08 19:54
ThatsAlok13-Mar-08 19:54 
GeneralRe: Virtual base class Pin
Hamid_RT23-Mar-08 1:16
Hamid_RT23-Mar-08 1:16 
GeneralRe: Virtual base class Pin
George_George23-Mar-08 3:15
George_George23-Mar-08 3:15 
QuestionHow to get ALT, SHIFT and CTRL key? Pin
TooShy2Talk13-Mar-08 15:32
TooShy2Talk13-Mar-08 15:32 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
Eytukan13-Mar-08 16:14
Eytukan13-Mar-08 16:14 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
TooShy2Talk13-Mar-08 16:38
TooShy2Talk13-Mar-08 16:38 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
Eytukan13-Mar-08 17:40
Eytukan13-Mar-08 17:40 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
Mahesh Kulkarni13-Mar-08 18:14
Mahesh Kulkarni13-Mar-08 18:14 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
ThatsAlok13-Mar-08 19:53
ThatsAlok13-Mar-08 19:53 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
Mahesh Kulkarni13-Mar-08 20:43
Mahesh Kulkarni13-Mar-08 20:43 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
TooShy2Talk13-Mar-08 21:16
TooShy2Talk13-Mar-08 21:16 
QuestionRe: How to get ALT, SHIFT and CTRL key? Pin
TooShy2Talk13-Mar-08 21:40
TooShy2Talk13-Mar-08 21:40 
GeneralRe: How to get ALT, SHIFT and CTRL key? Pin
Mahesh Kulkarni14-Mar-08 2:40
Mahesh Kulkarni14-Mar-08 2:40 
GeneralPimpl Idiom client/serve compile/link Pin
George_George13-Mar-08 15:26
George_George13-Mar-08 15:26 
GeneralAbout your opaque pointer Pin
Eytukan13-Mar-08 16:08
Eytukan13-Mar-08 16:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.