Advertisement

Inheritance and Friends

Started by May 07, 2001 06:22 PM
5 comments, last by kirkd 23 years, 9 months ago
Let''s suppose you have a base class from which a derived class inherits private members. If a friend funciton is declared in the derived class, shouldn''t it still have access to the private members inherited from the base class? Visual C++ 5.0 does not allow access to the private members declared in the base class by a friend of the derived class. Either it''s a bug or I don''t understand inheritance rules. Either is equally likely. 8^) -Kirk
A derived class CANNOT access the private members of the base class. It can access ONLY the PROTECTED and PUBLIC members of the base class. So, its friend class, which has the same privileges as itself CANNOT access the private members of the base class, but can access the protected and public members of the base class.

Arun
Advertisement
quote:

Either is equally likely. 8^)



Um not really. The chance that it''s just a bug in MSVC is almost impossible. Like 750000 to 1 like odds.
There is a section on msdn that details how friends work in C++. Here''s a link to one of the pages that might explain what you''re wondering about
In the meantime, this topic:
http://www.gamedev.net/community/forums/topic.asp?topic_id=47254

..gives this link..
http://support.microsoft.com/support/kb/articles/Q243/4/51.ASP

..which is a list of all the bugs (non-compliance issues) that are in MSVC 6.0. There ARE bugs in MSVC, about 10 of them. If yours isn''t one of these, odds are that your code''s at fault.
Friendship is neither inherited nor transitive.

"The C++Programming Language, " Stroustrup, p. 852
Advertisement
Thanks for all the replies. Especially the links!!

-Kirk

This topic is closed to new replies.

Advertisement