From -7937167317887714674
X-Google-Thread: f78e5,13848293b54382c8
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 19 Apr 2006 12:20:02 -0500
Return-Path: <devnull@stump.algebra.com>
X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on ak74.algebra.com
X-Spam-Level: ***
X-Spam-Status: No, score=3.4 required=5.0 tests=HEADER_SPAM,MISSING_HEADERS,
	TO_CC_NONE autolearn=disabled version=3.1.1
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@ucar.edu
From: "SuperKoko" <tabkannaz@yahoo.fr>
Newsgroups: comp.std.c++
Subject: Re: Encapsulation of variables
Organization: http://groups.google.com
Message-ID: <1145464591.411704.314680@j33g2000cwa.googlegroups.com>
References: <1145365947.835536.81010@u72g2000cwu.googlegroups.com>
   <4Te1g.87563$PR2.1399736@twister2.libero.it>
   <1145433404.436690.81060@e56g2000cwe.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 styx.pedago1.unicaen.fr:3128 (squid/2.5.STABLE6), 1.0 proxy2.unicaen.fr:3128 (squid/2.5.STABLE9), 1.0 groups.google.com
Complaints-To: groups-abuse@google.com
Injection-Info: j33g2000cwa.googlegroups.com; posting-host=193.55.130.208;
   posting-account=vOfC2w0AAABzHsIWnglmMRchI1pVxsvC
X-Greylisting: NO DELAY (Relay+Sender autoqualified);
	processed by UCSD_GL-v2.1 on mailbox4.ucsd.edu;
	Wed, 19 April 2006 09:36:40 -0700 (PDT)
X-Spamscanner: mailbox4.ucsd.edu  (v1.6 Aug  4 2005 15:27:38, -2.8/5.0 3.0.4)
X-MailScanner: PASSED (v1.2.8 4702 k3JGacoA020117 mailbox4.ucsd.edu)
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
Date: Wed, 19 Apr 2006 12:18:10 CST
Lines: 56
NNTP-Posting-Host: 65.182.171.162
X-Trace: sv3-C1IXYsKvtkwkl2cxjxvodxStywiaJV2gi2jwYLArcT+gUsukDK8h0Cl0mmZR6fj04aA/+EZL1OHnHBn!9qc2x+uSTzNUdXNsFJIHOWs4FRUKwJPSc14uLv+/SquhbdoYeRXnPHcXkwZKYMTMQHfQhwG6PjzP!NrDwQG5st7pcTSny26h8hQoEEKlv9kCaZMoZ5EUPeyY=
X-Complaints-To: abuse@speakeasy.net
X-DMCA-Complaints-To: abuse@speakeasy.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
Xref: g2news1.google.com comp.std.c++:1615

philparsonage@hotmail.com wrote:
> OK, so maybe my example wasn't the best, I typed a private instead of a
> protected. The actual code (which compiles using 4.0.2, or 3.3.6) is:
>
> #include <stdlib.h>
>
> class A {
>   protected: int _fred;
>   /// no-one can see fred directly
> };
>
> class B : public A {
>   public : using A::_fred;
>   /// but this magically turns A::_fred to be public!
> };
>
> int main(int argc, char** argv)
> {
>   B b;
>   b._fred  = 10; // you can do this
>   return 0;
> }
>
This code is fine.
class B derives from class A, and so, is perfectly aware of all
protected members of A.
Thus, it can expose them to everybody.
That's not much different from:
 class B : public A {
   public : int& fred() {return _fred;}
 };

Similarly, using directives can be used to expose privately inherited
members.
class B : private A
public: using A::_fred;
}

Of course, having a public data member in a non-aggregate class, is
usually a sign of bad design... But the point here was the correctness
of data hiding.

The morale here, is that "protected" is nearly equivalent, in terms of
contract, to "public".
A "protected" member is NOT private!
If you write a class with protected members, you make the contract that
you'll not change these members in future...

That is also why, protected data members are a bad idea.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



