fork download
  1. #include <iostream>
  2.  
  3. class Foo {
  4. public:
  5. int m_i; // member variable, m_xxx
  6. Foo(int); // constructor taking an int.
  7. };
  8.  
  9. static int s_i;
  10.  
  11. Foo::Foo(int i_) // arguments use _ suffix
  12. {
  13. int i = i_; // local value of i
  14. i *= 3;
  15. m_i = i; // we're assigning it the local value, not the argument.
  16. }
  17.  
  18. int main()
  19. {
  20. int i = 1;
  21. Foo foo(2);
  22. s_i = 3;
  23.  
  24. std::cout << "i = "<<i<<", foo.m_i = "<<foo.m_i<<", s_i = "<<s_i<< std::endl;
  25. }
  26.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
i = 1, foo.m_i = 6, s_i = 3