Using a class instead of struct. : Struct Class « Class « C++






Using a class instead of struct.

  
#include <iostream>  
using namespace std;     
class MyClass {  
  int i;// private by default  
public:  
  int get_i(void);  
  void put_i(int j);  
} ;  
     
int MyClass::get_i(void)  
{  
  return i;  
}  
     
void MyClass::put_i(int j)  
{  
  i = j;  
}  
     
main(void)  
{  
  MyClass s;  
     
  s.put_i(10);  
  cout << s.get_i();  
     
  return 0;  
}
  
    
  








Related examples in the same category

1.Constructor and destructor inside a structConstructor and destructor inside a struct
2.Stack class using a structure.Stack class using a structure.
3.Using a structure to define a class.Using a structure to define a class.
4.Classes and Structures are Related
5.add method to struct
6.use struct to initialize a class