Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15109
| Date | 2012-03-30 18:53 +0100 |
|---|---|
| From | Leigh Johnston <leigh@i42.co.uk> |
| Newsgroups | comp.lang.c++ |
| Subject | litb is teh famous (private access specifier is private no more) |
| Message-ID | <r_WdnZDF0_abbujSnZ2dnUVZ8j2dnZ2d@giganews.com> (permalink) |
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.
<code>
template<typename Tag, typename Tag::type M>
struct Rob {
friend typename Tag::type get(Tag) {
return M;
}
};
// use
struct A {
A(int a):a(a) { }
private:
int a;
};
// tag used to access A::a
struct A_f {
typedef int A::*type;
friend type get(A_f);
};
template struct Rob<A_f, &A::a>;
int main() {
A a(42);
std::cout << "proof: " << a.*get(A_f()) << std::endl;
}
</code>
<output>
proof: 42
</output>
http://bloglitb.blogspot.co.uk/2011/12/access-to-private-members-safer.html
/Leigh
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll 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