Click here to Skip to main content
15,898,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Virtual base class constructor Pin
George_George24-Mar-08 3:01
George_George24-Mar-08 3:01 
GeneralRe: Virtual base class constructor Pin
CPallini24-Mar-08 6:11
mveCPallini24-Mar-08 6:11 
GeneralRe: Virtual base class constructor Pin
George_George24-Mar-08 21:26
George_George24-Mar-08 21:26 
GeneralRe: Virtual base class constructor Pin
CPallini24-Mar-08 23:36
mveCPallini24-Mar-08 23:36 
GeneralRe: Virtual base class constructor Pin
George_George25-Mar-08 3:00
George_George25-Mar-08 3:00 
GeneralRe: Virtual base class constructor Pin
CPallini25-Mar-08 5:08
mveCPallini25-Mar-08 5:08 
GeneralRe: Virtual base class constructor Pin
George_George25-Mar-08 20:36
George_George25-Mar-08 20:36 
GeneralRe: Virtual base class constructor Pin
CPallini25-Mar-08 22:45
mveCPallini25-Mar-08 22:45 
Indeed you're right: with respect thew original article, we made a big mistake Blush | :O .

I think the right code to show the issue is, for instance
#include <iostream>

using namespace std;

class A
{
	int a;public:	A(){a=0;}	
	virtual int do_things(int a){this->a = a; return 0;}
};

class AB: virtual public A
{	
	int ab;
public:
	AB(){ab=1; A * pA = this; pA->do_things(1);}
	virtual int do_things(int a){A::do_things(a);this->ab = a+1; return 1;}
};

class AC: virtual public A
{
	int ac;
public:	
	AC(){ac=2; A * pA = this; pA->do_things(2);}
	virtual int do_things(int a){A::do_things(a);this->ac = a+2; return 2;}
};

class ABAC: public AB, public AC
{
	int abac;
public:
	ABAC(){abac = 4;}
	virtual int do_things(int a){AB::do_things(a);AC::do_things(a);this->abac = a+4; return 4;}
};

int main()
{
	ABAC abac;

	return 0;
}


that produce the following memory layout:
-		abac	{abac=4 }	ABAC
-		AB	{ab=2 }	AB
-		A	{a=2 }	A
-		__vfptr	0x00415700 const ABAC::`vftable'	*
		[0]	0x0041122b [thunk]:ABAC::do_things`vtordisp{4294967292,0}' (int)	*
		a	2	int
		ab	2	int
-		AC	{ac=4 }	AC
-		A	{a=2 }	A
-		__vfptr	0x00415700 const ABAC::`vftable'	*
		[0]	0x0041122b [thunk]:ABAC::do_things`vtordisp{4294967292,0}' (int)	*
		a	2	int
		ac	4	int
		abac	4	int


If you try to compile and run it using #pragma vtordisp(off) then you get a runtime error (hence the usefulness of vtordisp).
Don't ask me the interpretation of vtordisp{4294967292,0}, at the moment I'm not able to... (though 4294967292 is -3, an offset?).
Perhaps the argument needs more investigation.
BTW was you [^]?
See also this one [^], it's interesting.
Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke


GeneralRe: Virtual base class constructor Pin
George_George25-Mar-08 23:30
George_George25-Mar-08 23:30 
Generalcode for active x controls in vc++ Pin
kumartnvr23-Mar-08 2:54
kumartnvr23-Mar-08 2:54 
GeneralRe: code for active x controls in vc++ Pin
CPallini23-Mar-08 4:20
mveCPallini23-Mar-08 4:20 
Generalextended style problem, compiles but not take effect Pin
followait22-Mar-08 22:49
followait22-Mar-08 22:49 
QuestionRe: extended style problem, compiles but not take effect Pin
CPallini23-Mar-08 0:30
mveCPallini23-Mar-08 0:30 
GeneralRe: extended style problem, compiles but not take effect Pin
followait23-Mar-08 0:57
followait23-Mar-08 0:57 
Questioni want to make usb control system~give me tip please~ Pin
Jung Seng Won22-Mar-08 19:27
Jung Seng Won22-Mar-08 19:27 
GeneralRe: i want to make usb control system~give me tip please~ Pin
CPallini23-Mar-08 0:36
mveCPallini23-Mar-08 0:36 
QuestionUnhandle exception in DAO350.dll Pin
clever10122-Mar-08 17:27
clever10122-Mar-08 17:27 
GeneralRe: Unhandle exception in DAO350.dll Pin
Mark Salsbery23-Mar-08 7:17
Mark Salsbery23-Mar-08 7:17 
QuestionHow to submit (ie control) Pin
chinakknd22-Mar-08 16:05
chinakknd22-Mar-08 16:05 
AnswerRe: How to submit (ie control) Pin
Rajkumar R22-Mar-08 23:56
Rajkumar R22-Mar-08 23:56 
GeneralRe: How to submit (ie control) Pin
chinakknd23-Mar-08 15:38
chinakknd23-Mar-08 15:38 
GeneralRe: How to submit (ie control) Pin
Rajkumar R23-Mar-08 18:17
Rajkumar R23-Mar-08 18:17 
GeneralRe: How to submit (ie control) Pin
chinakknd24-Mar-08 16:14
chinakknd24-Mar-08 16:14 
GeneralSetting the cursor for MFC MDI child windows Pin
Californian222-Mar-08 12:34
Californian222-Mar-08 12:34 
GeneralRe: Setting the cursor for MFC MDI child windows Pin
Rajkumar R22-Mar-08 20:47
Rajkumar R22-Mar-08 20:47 

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.