Advertisement
Guest User

Private/Public Example

a guest
Jul 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. class Test
  2. {
  3. public:
  4.  
  5. void displayPrivateNo()
  6. {
  7. std::cout << privateNo << std::endl;
  8. }
  9.  
  10. private:
  11. int privateNo{ 1337 };
  12. };
  13.  
  14. int main()
  15. {
  16. Test test;
  17.  
  18. test.displayPrivateNo(); //Works because displayPrivateNo calls the integer privateNo within the class
  19. //std::cout << test.privateNo << std::endl; //Doesnt work because privateNo gets called outside of the class
  20.  
  21. system("pause");
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement