您的位置:首页 > 其它

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

2014-04-17 10:27 260 查看
例子

typedef struct
{
std:string features;
} Row;

Row row;

row.feautres = "hello";

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

参考:
http://stackoverflow.com/questions/20452581/segmentation-fault-assigning-stdstring-in-a-struct http://stackoverflow.com/questions/3411815/how-to-use-a-c-string-in-a-structure-when-malloc-ing-the-same-structure
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: