fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Test{
  5.  
  6. int myVar;
  7. static int myStaticVar;
  8.  
  9. void MyFunction()
  10. {
  11. myVar = 1; // Line 1
  12. myStaticVar = 1; // Line 2
  13. }
  14.  
  15. void static MyStaticFunction()
  16. {
  17. myVar = 1; // Line 3
  18. myStaticVar = 1; // Line 4
  19. }
  20.  
  21. };
  22.  
  23.  
  24. int main() {
  25. // your code goes here
  26. Test t;
  27. t.MyFunction();
  28. Test :: MyStaticFunction();
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static void Test::MyStaticFunction()’:
prog.cpp:17:2: error: invalid use of member ‘Test::myVar’ in static member function
  myVar = 1;  // Line 3
  ^~~~~
prog.cpp:6:5: note: declared here
 int myVar;
     ^~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:27:15: error: ‘void Test::MyFunction()’ is private within this context
  t.MyFunction();
               ^
prog.cpp:9:6: note: declared private here
 void MyFunction()
      ^~~~~~~~~~
prog.cpp:28:27: error: ‘static void Test::MyStaticFunction()’ is private within this context
  Test :: MyStaticFunction();
                           ^
prog.cpp:15:13: note: declared private here
 void static MyStaticFunction()
             ^~~~~~~~~~~~~~~~
stdout
Standard output is empty