Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #15114

Re: litb is teh famous (private access specifier is private no more)

From Gareth Owen <gwowen@gmail.com>
Newsgroups comp.lang.c++
Subject Re: litb is teh famous (private access specifier is private no more)
References <r_WdnZDF0_abbujSnZ2dnUVZ8j2dnZ2d@giganews.com>
Date 2012-03-31 08:37 +0100
Message-ID <87k421xlt4.fsf@gmail.com> (permalink)

Show all headers | View raw


Leigh Johnston <leigh@i42.co.uk> 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."

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

litb is teh famous (private access specifier is private no more) Leigh Johnston <leigh@i42.co.uk> - 2012-03-30 18:53 +0100
  Re: litb is teh famous (private access specifier is private no more) Gareth Owen <gwowen@gmail.com> - 2012-03-31 08:37 +0100
  Re: litb is teh famous (private access specifier is private no more) jacob navia <jacob@spamsink.net> - 2012-03-31 10:47 +0200
    Re: litb is teh famous (private access specifier is private no more) gwowen <gwowen@gmail.com> - 2012-04-03 04:14 -0700
  Re: litb is teh famous (private access specifier is private no more) TJorgenson <tjorgenson@infinera.com> - 2012-03-30 21:29 -0700

csiph-web