Question #213003

Write a program having class STRING, With data member which can store character array (Dynamically you can store). It should facility to initialize by parameterize constructor and concatenate STRING objects.

Ex:   STRING  obj1(“OOP”), obj2 (“IN KIIT”);

         Obj1 = obj1 + obj2;

Then obj1 should have “ OOP IN KIIT”   string in it. 



Expert's answer

#include <iostream>

using namespace std;

class String {
  string val;
  
  String(string val) {
    this->val = val;
  }
}

String * operator+ (const String &a, const String &b) {
  return new String(a.val + b.val);
}

int main() {}
LATEST TUTORIALS
APPROVED BY CLIENTS