Question
Write a member function of a class MyString that overloads the + operator. This function returns a const MyString that is the concatenation of 2
Write a member function of a class MyString that overloads the + operator. This function returns a const MyString that is the concatenation of 2 MyString objects (i.e., MyString is your own version of the string class and you are overloading the + operator to work just like the string class + operator). You may use any of the functions declared below if you want. You may declare and use any private helper functions if you want. But you must also implement any private helper function you use. Something you need to take think about and take care of is making sure the cstring in cstr is large enough to store the concatenated cstrings. If needed, you may increase the capacity of cstr (i.e. the size of the cstr array) by any amount you want. class MyString { private: unsigned sz; //stores the current length of the MyString unsigned cap; //stores the capacity of the cstring cstr char *cstr; //stores a dynamically allocated cstring public: MyString(); //constructs an empty MyString (i.e., "") MyString(const char *); //makes a copy of the cstring MyString(const MyString &); //performs deep copy ~MyString(); //deallocates the array unsigned length() const; //returns the length of the string const char * c_str() const; //returns the cstring cstr //many other public member functions would be declared here //declare your + operator function here as a public member //function private: //you may declare any private helper functions here if you want
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started