struct 和 (對象)std:string不要混用

例子對象

typedef struct
{
   std:string  features;
} Row;內存

 

Row row;string

row.feautres = "hello";io

可能出錯,由於struct分配的時候,僅僅是分配內存空間,並無對裏面的對象進行必要的初始化,這樣就有可能到只row.features.assign(xxx)報錯segment fault(機率性的)stackoverflow

 

參考:co

  1. http://stackoverflow.com/questions/20452581/segmentation-fault-assigning-stdstring-in-a-struct
  2. http://stackoverflow.com/questions/3411815/how-to-use-a-c-string-in-a-structure-when-malloc-ing-the-same-structure
相關文章
相關標籤/搜索