Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Sat, 31 Mar 2012 02:37:54 -0500 From: Gareth Owen Newsgroups: comp.lang.c++ Subject: Re: litb is teh famous (private access specifier is private no more) References: Date: Sat, 31 Mar 2012 08:37:59 +0100 Message-ID: <87k421xlt4.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:5oNDKfainpjrrU5h8unShZKeB+E= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 35 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-nw7gzFdJxX1F4YnGC7K5GM53hbvY5v2RxJns7BrepKLSxNmD1yFaB39vbkgD8F47Prhp6UDC1I0/25C!cpcK3fPS9Yxiax8uTi5nkEtoJ0Lm2NNUEu/58emeJnFie6ekaaPW5Vkrv7GF3ijHVYc= 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.40 X-Original-Bytes: 2752 Xref: csiph.com comp.lang.c++:15114 Leigh Johnston writes: > Should the C++ standard be changed to stop litb's cool (and legal) > hack to bypass private access specifier? Bypassing private is very > bad IMO. It's a very neat hack, but private doesn't mean secret. There are already ways to get at private and protected data members. litb's hack appears to be a variant of Herb Sutter's Person #4 ( http://www.gotw.ca/gotw/076.htm ) I'll quote Herb's summation, which answers the problem pretty succinctly, and with which I agree: "This demonstrates an interesting interaction between two C++ features: The access control model, and the template model. It turns out that member templates appear to implicitly "break encapsulation" in the sense that they effectively provide a portable way to bypass the class access control mechanism." "This isn't actually a problem. The issue here is of protecting against Murphy vs. protecting against Machiavelli... that is, protecting against accidental misuse (which the language does very well) vs. protecting against deliberate abuse (which is effectively impossible). In the end, if a programmer wants badly enough to subvert the system, he'll find a way, as demonstrated above in Examples 1 to 3." "The real answer to the issue is: Don't do that! Admittedly, even Scott Meyers has said publicly that there are times when it's tempting to have a quick way to bypass the access control mechanism temporarily, such as to produce better diagnostic output during debugging... but it's just not a habit you want to get into for production code, and it should appear on the list of "one-warning offences" in your development shop."