Implement the copy assignment operator= for the StringVar class using the options given on the right side window. Place the code into the left side using the arrows. It is possible to get the test case correct but not complete NOTE: Be careful! There are decoys! The this pointer is used extensively.. Assume that StringVar.h has the following declaration: #include class StringVar { public: StringVar() : max_length(20) { // Default constructor size is 20 value = new char[max_length+1]; value[0] = '\0'; } StringVar(int size); // Takes an int for size StringVar(const char cstr[]); // Takes a c-string and copies it StringVar(const StringVar& strObj); // Copy Constructor ~StringVar(); // Destructor int size() const { return max_length; } // Access capacity const char* c_str() const { return value; } // Access value int length() const { return strlen(value); } // Access length StringVar& operator= (const StringVar& rightObj); std::istream& operator>> (std::istream& in, StringVar& strVar); std::ostream& operator<< (std::ostream& out, const StringVar& strVar); private: int max_length; char* value; };
Need help with a c++ building block question! Nongraded
Implement the copy assignment operator= for the StringVar class using the options given on the right side window. Place the code into the left side using the arrows. It is possible to get the test case correct but not complete
NOTE: Be careful! There are decoys! The this pointer is used extensively..
Assume that StringVar.h has the following declaration:
#include <iostream>
class StringVar {
public:
StringVar() : max_length(20) { // Default constructor size is 20
value = new char[max_length+1];
value[0] = '\0';
}
StringVar(int size); // Takes an int for size
StringVar(const char cstr[]); // Takes a c-string and copies it
StringVar(const StringVar& strObj); // Copy Constructor
~StringVar(); // Destructor
int size() const { return max_length; } // Access capacity
const char* c_str() const { return value; } // Access value
int length() const { return strlen(value); } // Access length
StringVar& operator= (const StringVar& rightObj);
std::istream& operator>> (std::istream& in, StringVar& strVar);
std::ostream& operator<< (std::ostream& out, const StringVar& strVar);
private:
int max_length;
char* value;
};
The image is the building block codes. Not all blocks need to be used!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps