在13.2.1节中
class HasPtr {
public:
HasPtr(const std::string &s = std::string()):
ps(new std::string(s)),i(0) { }
...
private:
std::string *ps;
int i;
为什么作为指针的ps可以用指向的字符串赋值,这里面“new”起了什么作用,去掉new就会因为string不能转换为string*。
你没学动态内存分配?new XXX表示在堆区申请一块XXX类型内存,返回内存指针。