Write an overloaded function to concatenate two strings using + operator overloading.
#include <iostream>
#include <string>
using namespace std;
class String {
private:
string str;
public:
String(string str){
this->str=str;
}
~String(){}
// overloaded function to concatenate two strings using + operator overloading.
string operator+(const String& other) {
return str.append(other.str);
}
};
int main(){
String string1="I like ";
String string2="programming";
string sum=string1+string2;
cout<<sum<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment