Created
August 14, 2014 16:40
-
-
Save cournape/bf17ac1186ae69150c57 to your computer and use it in GitHub Desktop.
privacy is dead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class Foo { | |
private: | |
int m_value; | |
public: | |
Foo(int i) : m_value(i) {}; | |
int get_value(void) { return m_value; }; | |
}; | |
class Bar { | |
public: | |
int m_value; | |
}; | |
int main() | |
{ | |
Foo foo(1); | |
Bar *p_bar = reinterpret_cast<Bar*>(&foo); | |
std::cout << "foo value: " << (foo.get_value()) << std::endl; | |
// This fails | |
// foo.m = 2 | |
p_bar->m_value = 3; | |
std::cout << "foo value: " << (foo.get_value()) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment