#include <iostream>
class Example {
private :
int a;
public :
int getA( ) { return a; }
// Example class is immutable unless we add a setter method
// bool setA(int a2) {
// if (a2 < 100 && a2 >= 0) {
// a = a2;
// return true;
// } else {
// return false;
// }
// }
} ;
int main( ) {
Example e;
std:: cout << "e.a is " << e.a << std:: endl ;
e.a = 10 ;
// int n = -10;
// if (e.setA(n)) {
// std::cout << "e.a is now " << e.getA() << std::endl;
// } else {
// std::cout << "Could not set e.a to " << n << std::endl;
// }
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgRXhhbXBsZSB7CiAgICBwcml2YXRlOgogICAgICAgIGludCBhOwogICAgcHVibGljOgogICAgICAgIGludCBnZXRBKCkgeyByZXR1cm4gYTsgfQogICAgICAgIAogICAgICAgIC8vIEV4YW1wbGUgY2xhc3MgaXMgaW1tdXRhYmxlIHVubGVzcyB3ZSBhZGQgYSBzZXR0ZXIgbWV0aG9kCiAgICAgICAgLy8gYm9vbCBzZXRBKGludCBhMikgewogICAgICAgIC8vIAlpZiAoYTIgPCAxMDAgJiYgYTIgPj0gMCkgewogICAgICAgIC8vIAkJYSA9IGEyOwogICAgICAgIC8vIAkJcmV0dXJuIHRydWU7CiAgICAgICAgLy8gCX0gZWxzZSB7CiAgICAgICAgLy8gCQlyZXR1cm4gZmFsc2U7CiAgICAgICAgLy8gCX0KICAgICAgICAvLyB9Cn07CgppbnQgbWFpbigpIHsKCUV4YW1wbGUgZTsKCQoJc3RkOjpjb3V0IDw8ICJlLmEgaXMgIiA8PCBlLmEgPDwgc3RkOjplbmRsOwoJCgllLmEgPSAxMDsKCQoJLy8gaW50IG4gPSAtMTA7CgkvLyBpZiAoZS5zZXRBKG4pKSB7CgkvLyAJc3RkOjpjb3V0IDw8ICJlLmEgaXMgbm93ICIgPDwgZS5nZXRBKCkgPDwgc3RkOjplbmRsOwoJLy8gfSBlbHNlIHsKCS8vIAlzdGQ6OmNvdXQgPDwgIkNvdWxkIG5vdCBzZXQgZS5hIHRvICIgPDwgbiA8PCBzdGQ6OmVuZGw7CgkvLyB9Cn0=
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:30: error: ‘int Example::a’ is private within this context
std::cout << "e.a is " << e.a << std::endl;
^
prog.cpp:5:13: note: declared private here
int a;
^
prog.cpp:25:4: error: ‘int Example::a’ is private within this context
e.a = 10;
^
prog.cpp:5:13: note: declared private here
int a;
^
stdout