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

例子

typedef struct
{
   std:string  features;
} Row;

 

Row row;

row.feautres = "hello";

可能出错,因为struct分配的时候,仅仅是分配内存空间,并没有对里面的对象进行必要的初始化,这样就有可能到只row.features.assign(xxx)报错segment fault(概率性的)

 

参考:

  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

 

posted @ 2014-04-17 10:27  mongg  阅读(782)  评论(0编辑  收藏  举报