#include <string.h>
class String
{
public:
String(): data_(new char[1])
{
*data_ = '\0';
}
String(const char *str): data_(new char[strlen(str) + 1])
{
strcpy(data_, str);
}
String(const String &rhs): data_(new char[rhs.size() + 1])
{
strcpy(data_, rhs.c_str());
}
~String()
{
delete[] data_;
}
String& operator=(const String &rhs)
{
if (this == &rhs)
return *this;
delete[] data_;
data_ = new char[rhs.size() + 1];
strcpy(data_, rhs.c_str());
return *this;
}
size_t size() const
{
return strlen(data_);
}
const char* c_str() const
{
return data_;
}
private:
char* data_;
};
int main()
{
String s1;
String s2("hello");
s1 = s2;
String s3(s2);
}