Advertisements

Guest

> virtual int GetAge() const { return age; }
This code should not give you any error, unless you remove const from
the GetAge method in most base class. As you have declared the function
to be const in base class but not in derived class, it is not
overriding.

Also the virtual inheritance does not resolve the error for ambiguous
functions. You need to override the function in the most derived
(Griffin) class and call the appropriate base version.

Guest

I am sorry. What you told is correct. Actually when I override GetAge()
function it'll give errors. But one more is how can I print Eagle's
age? wrote:
> > virtual int GetAge() const { return age; }
> This code should not give you any error, unless you remove const from
> the GetAge method in most base class. As you have declared the function
> to be const in base class but not in derived class, it is not
> overriding.
>
> Also the virtual inheritance does not resolve the error for ambiguous
> functions. You need to override the function in the most derived
> (Griffin) class and call the appropriate base version.

Guest

wrote:
> I am sorry. What you told is correct. Actually when I override GetAge()
> function it'll give errors. But one more is how can I print Eagle's
> age?

If the functions are overriden properly, then by means of virtual
mechanism the call to getAge will be resolved correctly. But in Griffin
class you will have to override the function and hardcode which version
of gateAge should be called (Eagle::getAge OR Lion::getAge()) to avoid
ambiguous error.

Why dont you just write a bot to post your "OT" responses? It would save
you a lot of time. In about 20 posts you have added help possibly once :
in all the rest you are "OT"ing and referring to netiquette
documents.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!