C++ Program to Overload Subscript or array of index [] operator

Problem:

Write a C++ program to overload subscript or array of index operator. Write a C++ program to overload addition + operator for a message string.

C++ Program / Source Code:

Here is the source code of C++ program to overload subscript or array of index [] operator
/* Aim: Write a C++ program to overload subscript operator [] or array of index operator. */

#include<iostream>
#include<string.h>
using namespace std;

class message
{
     public:
     
     char msg[100];
     int l=strlen(msg);

     public:

     message()
     {
         strcpy(msg," ");
     }

     message(char str[100])
     {
         strcpy(msg,str);
     }

     message operator +(message m1)
     {
         message tmp;
         strcpy(tmp.msg,strcat(msg,m1.msg));  
         return tmp;
     }

     char operator [](const int index)
     {
         for(int i=0;msg[i]!='\0';i++)
         { 
             if(i==index)
             return msg[i];
         }
     } 

     const message& operator =(const message& m)
     {
          strcpy(msg,m.msg);
          return *this;
     } 

     friend void display();
};

void display(message m3)
{
  cout<<m3.msg;
}

int main()
{
 message m1("Abhijit"),m2("Kokane"),m3;
 
 cout<<" First string is ";
 display(m1);
 cout<<endl<<" Second string is ";
 display(m2);
 cout<<endl<<" Concatenation is ";
 display(m1+m2);
 cout<<endl<<" Character at position 1 of first string is "<<m1[1];
 cout<<endl<<" Assigning all strings equal to Abhijit i.e m1...";
 m3=m2=m1;
 cout<<endl<<" Second string is ";
 display(m2);
 cout<<endl<<" Second string is ";
 display(m3);
 cout<<endl;
 return 0;
}

/* Output of above code:- 

 First string is Abhijit
 Second string is Kokane
 Concatenation is AbhijitKokane
 Character at position 1 of first string is b
 Assigning all strings equal to AbhijitKokane i.e m1...
 Second string is AbhijitKokane
 Third string is AbhijitKokane

*/