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
相关文章
相关标签/搜索