Click here to Skip to main content
15,915,703 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Thread - Process synchronization Pin
Blake Miller19-May-05 5:22
Blake Miller19-May-05 5:22 
GeneralProblems with std::map Pin
ChemmieBro19-May-05 2:31
ChemmieBro19-May-05 2:31 
GeneralRe: Problems with std::map Pin
Joaquín M López Muñoz19-May-05 3:08
Joaquín M López Muñoz19-May-05 3:08 
GeneralRe: Problems with std::map Pin
ChemmieBro19-May-05 3:27
ChemmieBro19-May-05 3:27 
GeneralRe: Problems with std::map Pin
Joaquín M López Muñoz19-May-05 3:34
Joaquín M López Muñoz19-May-05 3:34 
GeneralRe: Problems with std::map Pin
ChemmieBro19-May-05 4:13
ChemmieBro19-May-05 4:13 
Generalvirtual inheritance Pin
SimpleProgramer19-May-05 2:27
SimpleProgramer19-May-05 2:27 
GeneralRe: virtual inheritance Pin
Joaquín M López Muñoz19-May-05 2:56
Joaquín M López Muñoz19-May-05 2:56 
Change the definition of DD as follows:
class DD : public virtual D
{
DD(int a): <font color="#ff0000">B(a),</font> D(a) {printf ("DDD2%d\n",a);};
};
You may ask, why does one need to explicitly construct B, when D already does it? This is a fundamental characteristic of virtual inheritance. To illustrate the issue, consider the following class hierarchy:
struct Top
{
  Top(int x){...}
};
 
struct Middle1: virtual public Top
{
  Middle1(int x):Top(x){...}
};
 
struct Middle2: virtual public Top
{
  Middle2(int x):Top(x){...}
};
 
struct Bottom: public Middle1, public Middle2
{
  Bottom():Middle1(1), Middle2(2){}
};
As you know virtual inheritance makes Base objects contain only one instance of Top, like depicted in the diagram:
     Top
      /\
     /  \
    /    \
Middle1  Middle2
    \    /
     \  /
      \/
    Bottom
Now take a look at Bottom's constructor and ask yourself the following: How is the Top suboject of Bottom initialized? According to Middle1, it is constructed with x==1, but Middle2 calls Top's constructor with x==2...
The fundamental problem is that, when virtually inheriting from Top, one cannot assume exclusive rights to the derived-from class, as it is likely to be shared among other unrelated classes. Recognizing this problem, C++ dictates the following: a virtually derived-from class Top must be explicitly constructed from the most derived class constructor, and all other calls to constructors of Top are ignored. Hence your problem.
This issue does not arise to the surface when the Top class has a default constructor, which could be the reason why you haven't met the problem before. Hope this helps.


Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
Questionhow to copy and paste a nonregular area of an image Pin
Anonymous19-May-05 1:19
Anonymous19-May-05 1:19 
AnswerRe: how to copy and paste a nonregular area of an image Pin
Chris Losinger19-May-05 3:50
professionalChris Losinger19-May-05 3:50 
Generalfile type associations Pin
gx4419-May-05 0:58
gx4419-May-05 0:58 
GeneralRe: file type associations Pin
Joel Holdsworth19-May-05 1:11
Joel Holdsworth19-May-05 1:11 
QuestionCross Network communication using Winsock2? Pin
arrya_amit19-May-05 0:39
arrya_amit19-May-05 0:39 
AnswerRe: Cross Network communication using Winsock2? Pin
ThatsAlok19-May-05 1:44
ThatsAlok19-May-05 1:44 
Generalsimple installer Pin
dave2k19-May-05 0:16
dave2k19-May-05 0:16 
GeneralRe: simple installer Pin
Jack Puppy19-May-05 0:19
Jack Puppy19-May-05 0:19 
GeneralDAO and ADO in same project Pin
MK7818-May-05 22:47
MK7818-May-05 22:47 
GeneralRe: DAO and ADO in same project Pin
RChin18-May-05 23:49
RChin18-May-05 23:49 
GeneralRe: DAO and ADO in same project Pin
MK7818-May-05 23:59
MK7818-May-05 23:59 
GeneralRe: DAO and ADO in same project Pin
RChin19-May-05 0:22
RChin19-May-05 0:22 
GeneralRe: DAO and ADO in same project Pin
MK7819-May-05 1:47
MK7819-May-05 1:47 
GeneralProblems with a dll Pin
JaVinci18-May-05 22:27
JaVinci18-May-05 22:27 
GeneralRe: Problems with a dll Pin
GDavy19-May-05 0:00
GDavy19-May-05 0:00 
GeneralRe: Problems with a dll Pin
JaVinci19-May-05 3:50
JaVinci19-May-05 3:50 
QuestionWhat is #pragma pack()? Pin
xSoptik18-May-05 21:31
xSoptik18-May-05 21:31 

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.