473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Problem with multiple inheritance

Hi there,

besides I always check this forum about my doutbs this is my first post here. In fact, this problem is boring me for a day and could not find an answer yet :-(

The scenario is illustrated bellow with code snipets:
Expand|Select|Wrap|Line Numbers
  1. //MStreamError.h
  2.  
  3. class MStreamError {
  4. private:
  5.     char* mesg;
  6.  
  7. public:
  8.  
  9.     explicit MStreamError( const char* msg ) {
  10.         //impl...
  11.     }
  12.  
  13.     ~MStreamError() {
  14.         //impl...
  15.     }
  16.  
  17.     void report() const {
  18.         //impl...
  19.     }
  20.  
  21.     const char* get_message() {
  22.         //impl...
  23.     }
  24. };
  25.  
  26. //ServerRuntimeErrors.h
  27.  
  28. class ServerRuntimeErrors : public virtual MStreamError {
  29. public:
  30.     ServerRuntimeErrors( const char* errorMessage ) : MStreamError( errorMessage ) {}
  31. };
  32.  
  33. //ClientRuntimeErrors.h
  34.  
  35. class ClientRuntimeErrors : public virtual MStreamError {
  36. public:
  37.     ClientRuntimeErrors( const char* errorMessage ) : MStreamError( errorMessage ) {}
  38. };
  39.  
  40. //InterfaceInicializationError.h
  41.  
  42. class InterfaceInitializationError : public ServerRuntimeErrors, public ClientRuntimeErrors {
  43. public:
  44.  
  45.     InterfaceInitializationError( const char* msg ) {};
  46. };
  47.  
Well, my doubt is how to initialize InterfaceInitializationError since it inherits from both ClientRuntimeErrors and ServerRuntimeErrors. In fact, after following the compiler error messages, I tried putting " : MStreamError( msg ), ServerRuntimeErrors( msg ), ClientRuntimeErrors( msg )" just after the InterfaceInitializationError ctor, and it worked. However, I do not know is this solution (using virtual inheritance and this order of constructors) is correct, or even what is happening here...

I will be thankfull is someone could give me some hint about that or point me out some reference where I could understand this situation...

Regards!!
Apr 7 '07 #1
2 1339
weaknessforcats
9,208 Expert Mod 8TB
With multiple inheritance there are new compiler rules for calling base class
constructors:

THE COMPILER WON' T CALL THEM.

That means in a multiple inheritance constructor, you have explicitly call all of the base class contructors yourself. That includes ALL indirect base class coinstructors as well. Like this:

InterfaceInitializationError::InterfaceInitializat ionError( const char* msg )
: ServerRuntimeErrors(msg), ClientRuntimeErrors(msg)
{};

This is different from single inheritance where you are not allowed to call indirect base class constructors but only the the immediate base class constructor.
Apr 8 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Oh, I forgot:

Check out C++ Primer Plus Stephane Prata 5th Ed. Read section on "New Constructor Rules"
Apr 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point...
2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
3
by: Morten Aune Lyrstad | last post by:
Hi again! I'm having problems with inheritance. I have a base interface class called IObject. Next I have two other interfaces classes, IControl and ICommandMaster, which derives from IObject. ...
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
14
by: dl | last post by:
I have two classes, say A and B, both having a data member 'int n'; private in A, public in B. When I derive class C from both public A and public B, B::n should be visible to C while A::n...
2
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.