Classes and Structures are Related : Struct Class « Class « C++






Classes and Structures are Related

  
#include <iostream>  
using namespace std;

struct MyClass {  
  int get_i(void); // these are public by default  
  void put_i(int j); 
private:  
  int i;  
} ;  
     
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.Using a class instead of struct.
5.add method to struct
6.use struct to initialize a class