Who really has access to your class's internals? This Item is about forgers, cheats, pickpockets, and thieves and how to recognize and avoid them.
JG Question
What code can access the following parts of a class?
public
protected
private
Guru Question
Consider the following header file:
// File x.h//
class X {
public:
X() : private_(1) { /*...*/ }
template<class T>
void f(const T& t) { /*...*/ }
int Value() { return private_; }
// …
private:
int private_;
};
Demonstrate:
a non-standards-conforming and non-portable hack; and
a fully standards-conforming and portable technique
for any calling code to get direct access to this class's private_ member.
Is this a hole in C++'s access control mechanism, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.