Question: Need the operator=(const char* other) method definition. c++ class NString { private: char * stringArrayPointer = nullptr; // PTR to char, used to dynamically allocate
Need the operator=(const char* other) method definition. c++
class NString { private: char * stringArrayPointer = nullptr; // PTR to char, used to dynamically allocate an array of char size_t Capacity; // Keeps track of the # of elements in the string array size_t Size; // Stores current length of the C string stored in the string array public: NString(); // Default constructor NString(const char* other); // Initialization constructor NString(const NString& other); // Copy constructor ~NString(); //Destructor - calls clear() method NString& operator=(const NString& other);// Overloaded assignment operator NString operator=(const char* other);// Overloaded assignment operator c string *This Method**** size_t capacity() const; // Method to return the string capacity size_t size() const; // Method to return the string size. bool empty() const; // Method to return true if string size = 0. Otherwise return false void clear(); // Method to set string size and string cap to -. uses delete[] to del str array. void reverse(size_t n);// Modifies an object's string cap w/o chaning its size or contents bool operator==(const NString& rhs) const; // Return true if chars are idenditcal const char& operator[](size_t pos) const; // Returns element pos of the string array char& operator[](size_t pos); // Return element pos of the string array friend bool operator==(const char* lhs, const NString& rhs); // Returns true if chars are identical friend ostream& operator<<(ostream& lhs, const NString& rhs); // Overloading insertion op
};
The method should assign a c string (the string other) to an NString object (the object that called the method, pointed to by this) and it should return a NString reference
NString& NString::operator=(const char* other)
{
DEFINITION
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
