Advertisement
AlexLeo

A Test of Struct & Access Modifiers in C++

Nov 6th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. class CClass
  6. {
  7.     int CClassInt=1;
  8. };
  9.  
  10. class CClass2 : CClass
  11. {
  12. public:
  13.     int returnCClassInt()
  14.     {
  15.         return CClassInt;
  16.     }
  17. };
  18.  
  19. int main()
  20. {
  21.     CClass2 ccl1;
  22.  
  23.     cout << "CClassInt=" << ccl1.CClassInt() << '\n';
  24.  
  25.     //system("pause");
  26.     return 0;
  27. }
  28.  
  29. /************************************** Compiler Output **************************************
  30. |7|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]|
  31. ||In member function ‘int CClass2::returnCClassInt()’:|
  32. |7|error: ‘int CClass::CClassInt’ is private|
  33. |15|error: within this context|
  34. ||In function ‘int main()’:|
  35. |7|error: ‘int CClass::CClassInt’ is private|
  36. |23|error: within this context|
  37. |23|error: expression cannot be used as a function|
  38. ||=== Build failed: 5 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
  39. ************************************** Compiler Output **************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement