fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class example {
  5. private:
  6. int var;
  7. void do_something() {std::cout << "doing something" << std::endl;}
  8. };
  9.  
  10. int main() {
  11. example e;
  12.  
  13. e.var = 10;
  14. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:13:4: error: ‘int example::var’ is private within this context
  e.var = 10;
    ^~~
prog.cpp:6:9: note: declared private here
     int var;
         ^~~
stdout
Standard output is empty