Advertisement
lordasif

static class

Mar 31st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5.  
  6. using namespace std;
  7.  
  8. class myclass
  9. {
  10. static int x;
  11. public:
  12. void setx(int n)
  13. {
  14. x=n;
  15. }
  16. int getx()
  17. {
  18. return x;
  19. }
  20.  
  21. };
  22.  
  23. int myclass::x;
  24.  
  25. int main()
  26. {
  27. myclass o1, o2;
  28. o1.setx(9);
  29. cout<<o1.getx()<<endl;
  30. cout<<o2.getx()<<endl;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement