Guest User

Untitled

a guest
Oct 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. using namespace std;
  2.  
  3. class A {
  4. public:
  5. int m_variable = 5;
  6. }
  7.  
  8. include iostream>
  9.  
  10. using namespace std;
  11.  
  12. void B::method() {
  13. // Why do get an error stating 'invalid use of non-static data member on this line?
  14. int x = (A::m_variable) * 2;
  15. cout << x << endl;
  16. }
  17.  
  18. class B : public A {
  19. // ... whatever
  20. };
  21.  
  22. class B {
  23. // ... whatever
  24. private:
  25. A someVar;
  26. };
  27.  
  28. int x = someVar.m_variable * 2;
  29.  
  30. class A {
  31. public:
  32. static int m_variable;
  33. };
Add Comment
Please, Sign In to add comment