我需要在c ++中销毁一个字符串吗?

dav*_*n11 6 c++ stl

如果我在类中有一个字符串,则分配内存.我是否必须销毁析构函数中的字符串?例如

class A {
  string Test;
  A() {
    Test = "hello world";
  }

  A(string &name) {
    Test = name;
  }

  ~A() {
    // do I have to destroy the string here?
  }
}

我是一个旧的c/c ++(pre stl)程序员并重新使用c ++.字符串是否使用某些模板魔法自动销毁?

蒂亚,戴夫

Mar*_*rer 9

是.字符串和容器为您分配/解除分配.但是,一个指针容器并没有释放那些指针所指向的东西.你必须自己循环.