Effective C++学習ノート:条項3:mallocやfreeを使わずにできるだけnewやdeleteを使う

755 ワード

Effective C++学習ノート:条項3:mallocやfreeを使わずにできるだけnewやdeleteを使う
できるだけC++でmallocとfreeを使用しないでください.newとdeleteを混用するとエラーの発生確率が大幅に増加するからです.
string *stringarray1 =
static_cast<string*>(malloc(10 * sizeof(string)));
string *stringarray2 = new string[10];
    stringarray1     10 string     ,               ,          10 string     。
  stringarray1   , free( stringarray1);stringarray=null;  stringarray2   ,  delete []stringarray2;
stringarray2=NULL;malloc free           ,         !
 c++     malloc free   ,     malloc      free,   new        delete       。   
    new free malloc delete    ,       。