473,396 Members | 1,725 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,396 software developers and data experts.

accessing base class in multiple inheritance

Given:

struct a {
int db;
};

class b: public a{};
class c: public a{};

struct d: public b, public c {
int& dbb() {return b::db;}
int& dbc() {return c::db;}
};

class e: public d{};
class f: public d{};
class g: public d{};

class h:
public e,
public f,
public g {
void fine();
void not_fine();
};

I'd like to know why g++ accepts

void h::fine() {
e::dbb() = 1;
f::dbc() = 2;
}

but says that 'a' is an ambiguous base in

void h::not_fine() {
e::b::db = 1;
f::c::db = 1;
}

Thanks,
Robert
Jul 22 '05 #1
2 1116
Robert Swan wrote:
Given:

struct a {
int db;
};

class b: public a{};
class c: public a{};

struct d: public b, public c {
int& dbb() {return b::db;}
int& dbc() {return c::db;}
};

class e: public d{};
class f: public d{};
class g: public d{};

class h:
public e,
public f,
public g {
void fine();
void not_fine();
};

I'd like to know why g++ accepts

void h::fine() {
e::dbb() = 1;
f::dbc() = 2;
}

but says that 'a' is an ambiguous base in

void h::not_fine() {
e::b::db = 1;
f::c::db = 1;
}


It is an ambiguous base. Qualifying names doesn't help. In the
end the compiler still tries to take "this" (h*) and convert it to
a*, which it can't due to ambiguity.

The only way to disambiguate is to tell which part of '*this' you
intend on using:

void h::not_fine() {
static_cast<e*>(this)->b::db = 1;
static_cast<f*>(this)->c::db = 1;
}

V
Jul 22 '05 #2
FWIW, VC7.1 seems to have no complaints about your example.

--
Greg Schmidt gr***@trawna.com
Trawna Publications http://www.trawna.com/
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
5
by: Scott | last post by:
Hi All, Am I correct in assuming that there is no way to have a base pointer to an object that uses multiple inheritance? For example, class A { /* ... */ }; class B { /* ... */ };
2
by: Jessica | last post by:
I have a base class and a derived class, but I am getting errors when I try to access functions of the derived class. Simplified version of my code is as follows: //////////////// // test2.hh...
3
by: hurcan solter | last post by:
Consider the code fragment; class A { public: A(){} A(int prm):mprm(prm){} int mprm; }; class B:public A {
14
by: Jo | last post by:
Hi, Is there a generic way to access the (virtual) functions in the base class of a class? Like in: if (!this->Foo(something)) return(((Base*)this)->Foo(something)); // for a normal member...
4
by: Joseph Paterson | last post by:
Hi all, I'm having some trouble with the following code (simplified to show the problem) class Counter { protected: int m_counter; }
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
11
by: Rahul | last post by:
Hi Everyone, While working with Java, i came across super() which passes values to base class constructor from derived class constructor. I was wondering if this could be implemented in c++ by...
0
by: =?Utf-8?B?Zmplcm9uaW1v?= | last post by:
Hi all, As I mentioned in a previous thread (see 'Dbghelp, symbols and templates' in microsoft.public.windbg), we created a powerful symbol engine using dbghelp to dump the contents of the stack...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.