problem with protected members

This is a discussion on problem with protected members within the C++ Programming forums, part of the General Programming Boards category; I know that protected member of a class can be accessed by subclasses of the previous class.
But I have ...

Apparently a B object has only access to the protected members of its own base part (or another B object), but not any other A object. Follow matsp's advice. Don't try to use inheritance to force your way into the protected parts of a different class.

My wording was a bit incorrect. A B object can access the protected superclass parts of B objects. But if the other class is A (or C which is also derived from A) - in short, not of type B, then there's no access.

I'd also like to point out that it is already possible to implement B::add using the public interface of A.

Which may or may not be usable in your real code. May-be you could tell us what is actually the design problem that you are trying to solve here? Because if you have troubles like that and consider suspicious-looking casts (or making parent aware of children ) there might be problems with the broader design itself.

May-be you could tell us what is actually the design problem that you are trying to solve here? Because if you have troubles like that and consider suspicious-looking casts (or making parent aware of children ) there might be problems with the broader design itself.

I agree, it would be wise to consider the overall picture of what you are trying to solve before reaching to make a class a friend.

A Branch is a type of Tip? Not evrything is an inheritance relationship.
A Cat is a type of Mammal is a type of Animal is a type of LivingThing.
A Branch is not a Tip, nor is a Tip a Branch.

For a binary tree (generalize if necessary) a single Node type with dual pointers
to children and one back to the parent, and, if you wish, perhaps a Tree type
to hold the root and additional data. But a Node is not a Tree and a Tree is
not a Node, so inheritance does not apply. The Tree will _contain_ Nodes
(a Tree "has" Nodes, it is not a sub- or supertype of Node).