/* * What does this program print out? * * Alternate question: Add an operator= to the following class * so that it performs a deep copy. */ #include #include using namespace std; class string_holder { public: char *contents = 0; string_holder operator=(const char* other){ if(contents) delete contents; contents = new char[strlen(other)]; strcpy(contents, other); return *this; } }; int main(){ string_holder one; one = "gerbil"; string_holder two; two = one; two = "moose"; cout << one.contents << endl; cout << two.contents << endl; return 0; }