add method to struct : Struct Class « Class « C++






add method to struct

   
#include <iostream>
#include <string.h>
using namespace std;
struct Msg 
{
  char message[256];
  void show_message(void); 
};


struct UpperMsg 
{
   char message[256];
   void show_message(void); 
};


void Msg::show_message(void)
{
   cout << message;
}

void UpperMsg::show_message(void)
{
   cout << strupr(message);
}

int main(void)
{
   Msg book = { "C\n" };
   UpperMsg book_upr = { "P\n" };

   book.show_message();
   book_upr.show_message();
}
  
    
    
  








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.Using a class instead of struct.
6.use struct to initialize a class