Author |
Topic: Where are C++ gurus, also elab. on below quest. (Read 700 times) |
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Where are C++ gurus, also elab. on below quest.
« on: Jan 10th, 2005, 5:14pm » |
Quote Modify
|
WHat is the difference between? a) class base { public: base(); ~base(); void virtual func_1(); : : void virtual func_n(); }; class derived:public base{ public: derived(); ~derived(); void virtual func_1() : : void virtual func_n(); }; vs. b) class base { public: base(); ~base(); void virtual func_1(); : : void virtual func_n(); }; class derived: virtual public base{ public: derived(); ~derived(); void virtual func_1() : : void virtual func_n(); };
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
TenaliRaman
Uberpuzzler
I am no special. I am only passionately curious.
Gender:
Posts: 1001
|
|
Re: Where are C++ gurus, also elab. on below quest
« Reply #1 on: Jan 10th, 2005, 11:06pm » |
Quote Modify
|
I will give u a small hint. Let us say that we have four classes class A,B,C,D such that : Class B and Class C are derived from class A Class D is derived from Class B and Class C. Do u see any problem here? -- AI
|
« Last Edit: Jan 10th, 2005, 11:07pm by TenaliRaman » |
IP Logged |
Self discovery comes when a man measures himself against an obstacle - Antoine de Saint Exupery
|
|
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Re: Where are C++ gurus, also elab. on below quest
« Reply #2 on: Jan 10th, 2005, 11:10pm » |
Quote Modify
|
I know about this diamond problem clotted with ambiguity due to methods/variables duplicates; I am more interested as to how it works to prevent that thx ... cracker
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
TenaliRaman
Uberpuzzler
I am no special. I am only passionately curious.
Gender:
Posts: 1001
|
|
Re: Where are C++ gurus, also elab. on below quest
« Reply #3 on: Jan 11th, 2005, 5:54am » |
Quote Modify
|
This is straight from ANSI C++ Handbook How does C++ ensure that only a single instance of a virtual member exists, regardless of the number of classes derived from it? This is implementation-dependent. However, all implementations currently use an additional level of indirection to access a virtual base class, usually by means of pointer. //Note: this is a simplified description of iostream classes class ostream: virtual public ios { /*..*/ } class istream: virtual public ios { /*..*/ } class iostream : public istream, public ostream { /*..*/ } In other words, each object in the iostream hierarchy has a pointer to the shared instance of the ios subobject. The additional level of indirection has a slight performance overhead. It also implies that the location of virtual subobjects is not known at compile time; therefore, RTTI (RunTime Type Identification) might be needed to access virtual subobjects in some circumstances. When multiple inheritance is used, the memory layout of such an object is implementation-dependent. The compiler can rearrange the order of the inherited subobjects to improve memory alignment. In addition, a virtual base can be moved to a different memory location. Therefore, when you are using multiple inheritance, do not assume anything about the underlying memory layout of an object. -- AI
|
« Last Edit: Jan 11th, 2005, 5:56am by TenaliRaman » |
IP Logged |
Self discovery comes when a man measures himself against an obstacle - Antoine de Saint Exupery
|
|
|
|