Please support our C++ advertiser: Programming Forums
Views: 4928 | Replies: 4
![]() |
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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
<< 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
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
}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
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
<< 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
<< 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
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
}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
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. Or.
I found this would remove the ambiguity.
w.b::f();
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."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode