operator overload string concatenate

Solutions on MaxInterview for operator overload string concatenate by the best coders in the world

showing results for - "operator overload string concatenate"
Ella
01 Jun 2017
1#include <iostream>
2#include <string.h>
3using namespace std;
4
5class Name
6{
7    public:
8        char x[100];
9        Name(){}
10        Name(char x[])
11        {
12            strcpy(this->x,x);
13        }
14        
15        Name operator+(Name&y)
16        {
17            Name fullname;
18            strcat(this->x," ");
19            strcat(this->x,y.x);
20            strcpy(fullname.x,this->x);
21            return fullname;
22        }
23};
24
25int main()
26{
27    char fname[10], lname[10];
28    cin>>fname>>lname;
29    Name f(fname);
30    Name l(lname);
31    Name final=f+l;
32    cout<<final.x;
33    return 0;
34}