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

name collisions in multiple inheritance

Vam
my compiler doesn't compile the following:

struct Base1
{
virtual void F(){}
};

struct Base2
{
virtual void F(){}
};

struct Derived : public Base1, private Base2
{
}

int main()
{
Derived d;
d.F();

return 0;
}

It complains that F is ambiguous. But when I try to do

d.Base2::F();

it notices that Base2 is private and hence inaccessible. Is my compiler
broken in this regard? I know I can use 'using base1::F()' in my derived
class, or 'd.Base1::F()' in main(), but it surprises me that I have to.
Jul 23 '05 #1
2 2193
Vam

"Vam" <ie@explorem.com> wrote in message
news:37*************@individual.net...
my compiler doesn't compile the following:

struct Base1
{
virtual void F(){}
};

struct Base2
{
virtual void F(){}
};

struct Derived : public Base1, private Base2
{
}

int main()
{
Derived d;
d.F();

return 0;
}

It complains that F is ambiguous. But when I try to do

d.Base2::F();

it notices that Base2 is private and hence inaccessible. Is my compiler
broken in this regard? I know I can use 'using base1::F()' in my derived
class, or 'd.Base1::F()' in main(), but it surprises me that I have to.


Just some minor corrections, add a ; after the Derived struct declaration,
and the 'using base1::F' shouldn't have the trailing ().
Jul 23 '05 #2
Vam wrote:
my compiler doesn't compile the following:

struct Base1
{
virtual void F(){}
};

struct Base2
{
virtual void F(){}
};

struct Derived : public Base1, private Base2
{
}

int main()
{
Derived d;
d.F();

return 0;
}

It complains that F is ambiguous. But when I try to do

d.Base2::F();

it notices that Base2 is private and hence inaccessible. Is my compiler
broken in this regard?


No. In C++ access specifications have no effect on name resolution. The
"privateness" of 'Base2::F' does not prevent it from participating in
name resolution process. In other words, the compiler first tries to
resolve the name and only then starts to pay attention to the access
rights. In your case name 'F' is indeed ambiguous.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #3

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

Similar topics

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...
11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
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...
7
by: Adam Nielsen | last post by:
Hi everyone, I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
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...
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). --...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.