Skip to content

Instantly share code, notes, and snippets.

@dionyziz
Created October 25, 2013 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dionyziz/7160738 to your computer and use it in GitHub Desktop.
Save dionyziz/7160738 to your computer and use it in GitHub Desktop.
Try to access the private property of another object of the same class.
#include <cstdio>
class Test {
private:
int foo;
public:
Test(int foo_value) {
foo = foo_value;
}
int getFoo(Test* other) {
return other->foo;
}
};
int main() {
Test* a = new Test(5);
Test* b = new Test(10);
printf("%i\n", a->getFoo(b));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment