Created
October 25, 2013 19:45
-
-
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.
This file contains 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 <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