标签:bsp logs thread ++ blog 代码 构造 调用 stream
构造函数调用构造函数是会问题的.
外层函数返回的内存, 与被调用的构造函数返回的内存并不是一个内存.
错误示例代码如下:
msg_log(const char *name, const char* thread_name, const char *cfg_file, int type = STREAM, int level = MSG_ERROR) : _name(name), _thread_name(thread_name), _level(level), _type(type), logfp(0), _set_process(false), _set_line(false), _set_file(false) { if(cfg_file) msg_log::cs_conf_file = cfg_file; init(type, level); pthread_mutex_init(&createfile_mutex,NULL); } msg_log(const char *name, const char *cfg_file, int type = STREAM, int level = MSG_ERROR) : _name(name), _level(level), _type(type), logfp(0), _set_process(false), _set_line(false), _set_file(false) { msg_log(name, "", cfg_file, type, level); }
太多年没写C++了, debug了好久, 才发现问题出在哪里.
参考: http://www.cnblogs.com/chio/archive/2007/10/20/931043.html
[development][c++] C++构造函数调用构造函数
标签:bsp logs thread ++ blog 代码 构造 调用 stream
原文地址:http://www.cnblogs.com/hugetong/p/7794942.html