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

Multiple inheritance ambiguity

struct PrivateBase { };
struct PublicBase { };

void foo( PrivateBase ) { }
void foo( PublicBase ) { }

struct Derived : PublicBase, private PrivateBase { };

int main()
{
Derived d;
foo( d ); // ambiguous
}
Why doesn't the call to foo( d ) resolve to foo( PublicBase )? Is this
a language defect?

D.

May 25 '06 #1
2 1622
Daniel Mitchell wrote:
struct PrivateBase { };
struct PublicBase { };

void foo( PrivateBase ) { }
void foo( PublicBase ) { }

struct Derived : PublicBase, private PrivateBase { };

int main()
{
Derived d;
foo( d ); // ambiguous
}
Why doesn't the call to foo( d ) resolve to foo( PublicBase )? Is this
a language defect?


This is by design.

[Member access control]
11§4 It should be noted that it is access to members and base classes
that is controlled, not their visibility. Names of members are still
visible, and implicit conversions to base classes are still considered,
when those members and base classes are inaccessible. The
interpretation of a given construct is established without regard to
access control. [...]
Jonathan

May 25 '06 #2
Daniel Mitchell wrote:
struct PrivateBase { };
struct PublicBase { };

void foo( PrivateBase ) { }
void foo( PublicBase ) { }

struct Derived : PublicBase, private PrivateBase { };

int main()
{
Derived d;
foo( d ); // ambiguous
}
Why doesn't the call to foo( d ) resolve to foo( PublicBase )? Is this
a language defect?

D.


Well, first of all you need references or pointers for your parameters
to foo(). But leaving that aside, Derived can be converted to a
PrivateBase by the members of Derived (see
http://www.parashift.com/c++-faq-lit...html#faq-24.2),
so both versions of foo() need to participate in the overload
resolution in general. Consequently, you'll need to make your intention
explicit in the context of main().

Cheers! --M

May 25 '06 #3

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

Similar topics

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...
5
by: IvDČ | last post by:
During a project I ran into trouble when using multiple inheritance. I was able to resolve the problem, but was unable to really understand the reasons for the error. Here is a short example of...
5
by: Tony Johansson | last post by:
Hello Experts! I just play around just to try to understand this about multiple inheritance. You have all the class definition below and at the bottom you have the main program. So here I...
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
3
by: ernesto | last post by:
Hi everybody I have the following class declarations: class Interface { public: virtual char* getName() const = 0; }; class BaseClass : public Interface {
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...
21
by: raylopez99 | last post by:
Well, contrary to the implication in my 2000 textbook on C# (public beta version), C# does allow multiple inheritance, so long as it's serially chained as follows: class derived02 : derived01 {...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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
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
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...

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.