child class not inheriting access to private data area to another class

I implemented a orderedList class, which i defined to be a subclass of the list class. This way i only needed to define the add method.

But the problem is that i created a class called link to help with the development of the list class.

I specified list to be a friend of link.
But i noticed that the only way for the orderedList class to work propertly is if i specify orderedList to be a friend of link, too. This feels wierd because i thought that all subclasses of a class should be able to execute any operations that the parent class can.

Is there a way to get around this? ie. a way to make orderedList work without changing the definition of the link class.
Last edited on
This feels wierd because i thought that all subclasses of a class should be able to execute any operations that the parent class can.


Not quite. Friendship is not inherited. Just because my dad is friends with Jeff doesn't mean Jeff and I are friends. Likewise just because list is friends with link doesn't mean orderedList is friends with link.


As for "getting around it", it depends a lot on the situation. What exactly does link do, and why can't list just do that itself? Are any other classes using link?
Topic archived. No new replies allowed.