class RQ1
{
private:
char * st; // point to C-style string
public:
RQ1() { st = new char [1]; strcpy(st, " "); }
RQ1(const char * s)
{st = new char [strlen(s) + 1]; strcpy(st, s); }
RQ1(const RQ1 & rq)
{st = new char [strlen(rq,st) + 1]; strcpy(st, rq.st); }
-RQ1(l {delete [] st);
RQ & operateor=(const RQ & rq);
// more stuff
}; 如果想将char*st转换为使用string对象的声明。那么上面的哪些方法不再需要显式定义,是string对象自己就可以管理的?
#include <string> using namespace std; class RQ1 { private: string st; // a string object public: RQ1() : st(" ") {} RQ1(const char * s) : st(s) {} -RQ1() {}; // more stuff };不再需要显式复制构造函数、析构程序和赋值运算符,因为string对象提供了自己的内存管理功能。