RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 4928 | Replies: 4
Reply
Join Date: Jun 2005
Posts: 3
Reputation: gagan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gagan gagan is offline Offline
Newbie Poster

Help inheritance problem

  #1  
Jul 18th, 2005
i m having one doubt regarding hybrid inheritance . i m just a beginner so its not clear to me :confused:
DOUBT:
WHY THE FOLLOWING CODE IS GIVING AMBIGUITY ERROR

#include<iostream.h>
class a
{
public:
 void f()
 {
 cout<<"base class\n";
 }
};
class b:private a //visibility mode private
{
public:
 void f1()
 {
 cout<<"inheritance\n";
 }
};
class c:public a  //visibility mode public
{
public:
 void f2()
 {
 cout<<"hybrid\n";
 }
};
class d:public b,public c
void main()
{
d w;
w.f(); //giving ambiguity error
}
<< moderator edit: added [code][/code] tags >>

f():private member of class b
f():public member of class c
as private members are not inheritable therefore there should be no
ambiguity error as class d can access f() through only one available
path that of class c
f()'saccess by w
w(object of class d)--->class c--->class a

please clear my doubt
i shall be highly thankful
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Posts: 3
Reputation: gagan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gagan gagan is offline Offline
Newbie Poster

Help hybrid inheritance prob

  #2  
Jul 18th, 2005
<< moderator edit: merged threads >>

i m having one doubt regarding hybrid inheritance . i m just a beginner so its not clear to me
DOUBT:
WHY THE FOLLOWING CODE IS GIVING AMBIGUITY ERROR

#include<iostream.h>
class a
{
public:
 void f()
 {
 cout<<"base class\n";
 }
};
class b: private a //visibility mode private
{
public:
 void f1()
 {
 cout<<"inheritance\n";
 }
};
class c: public a  //visibility mode public
{
public:
 void f2()
 {
 cout<<"hybrid\n";
 }
};
class d: public b,public c
void main()
{
d w;
w.f(); //giving ambiguity error
}
<< moderator edit: added [code][/code] tags -- learn to do so yourself >>

f(): private member of class b
f(): public member of class c
as private members are not inheritable therefore there should be no
ambiguity error as class d can access f() through only one available
path that of class c
f()'saccess by w
w(object of class d)--->class c--->class a

please clear my doubt
i shall be highly thankful
Reply With Quote  
Join Date: Apr 2004
Posts: 3,764
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: inheritance problem

  #3  
Jul 18th, 2005
Not my strong suit here, but isn't f() inherited by both b and c since it is public in a? And as such, there is ambiguity between which f() you are calling: b::f() or c::f()?

I found this would remove the ambiguity.
   w.b::f();
Or.
   w.c::f();
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
Reply With Quote  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: hybrid inheritance prob

  #4  
Jul 18th, 2005
Just a suggestion, try changing the function "void f()" to be "virtual void f()" and see if that resolves the issue. If it's just one of your classes acting up, you'll be able to tell if b or c is the troublemaker. If it doesn't work... well, someone competent will be with you shortly.
Reply With Quote  
Join Date: Jun 2005
Posts: 3
Reputation: gagan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gagan gagan is offline Offline
Newbie Poster

Re: inheritance problem

  #5  
Jul 18th, 2005
thank u very much now my code is giving no ambiguity error but i have one
doubt regarding w.b()::f();
how class c object w can access f() through class b as f() is a private member of b
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:32 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC