topimaurola wrote:
> I did intent it the ways it was.
> 
> The idea was: 
> 
> 1. Why the inherited class isn't a friend of master class as a default. I see 
> that it is not (by standard), but is there a rationale to make standard such?

Because 'friend's have access to all member variables - protected and 
private.  Protected is a nice happy middle ground between public and 
private for derived classes only.


> 2. Why the class is friend of itself, by default (as it cannot be revoked, I 
> guess). This is by standard, too, but is there a rationale behind?

You are misunderstanding the use of 'friend'.  If possible, you should 
avoid 'friend' - it violates object oriented principles (essentially all 
member variables are the equivalent of 'public' to the friend class).


> 3. Why 1) and 2) are different? is the main point. The inherited class should 
> be (from my feeling) be an extension of base class, with similar rights, but 
> that seems not to be the case.

You CAN modify the base class protected variables - but only in the 
current instance's derived class.

> I have a real-case where a derived-class object is trying to modify another 
> object of reference to base class, and it cannot access protected members.
> Similar code in base class works fine.
> 
> Topi

It sounds like the 'virtual' keyword might be useful here.  Your derived 
classes and base class have a function of the same name and parameters. 
  You pass the base class to a target function and call the virtual 
function, which calls the function in the derived class.  You should 
already be familiar with using 'virtual' as it is necessary for all 
destructors to be called properly in a derived/base class hierarchy.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to