[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: accessing protected members of a parent class
From:       Roberto Alsina <ralsina () kde ! org>
Date:       2002-04-04 17:56:48
[Download RAW message or body]

On Thu, 4 Apr 2002, Ellis Whitehead wrote:

> On Thursday 04 April 2002 11:40, Patrick Julien wrote:
> > you have to make B a friend in the protected or private section of class A.
> 
> That is in fact what I've been doing to get around the problem.  But its 
> ugliness quotient is horrendous and you can only use this approach for 
> sub-classes which you program yourself -- leaving the option unavailable to 
> programmers using the library...

Ok, the real answer is: "you are not supposed to access protected members
of the parent class".

If the guy that designed the class wanted you to access that member, he
would have made the member public.

Now, of course, that has some problems. It could be caused by bad design
of the class, causing your need to access the member. In that case, you
can just copy the class and make the member public, or your class a
friend, etc.

Or it could be caused because that member is going to change in a coming
version, and then by using it you make your app harder to port to the new
one. But this is minor.

Of course you can use some strategically placed 

#define protected public

which is a gross hack but works on most compilers.

 ("\''/").__..-''"`-. .         Roberto Alsina
 `9_ 9  )   `-. (    ).`-._.`)  ralsina@kde.org
 (_Y_.)' ._   ) `._`.  " -.-'   KDE Developer (MFCH)
  _..`-'_..-_/ /-'_.'           
(l)-'' ((i).' ((!.'             Buenos Aires - Argentina
Futuaris nisi irrisus ridebis. (Carlton, De rerum comoedia)


 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic