1. 程式人生 > >[development][c++] C++構造函數調用構造函數

[development][c++] C++構造函數調用構造函數

erro 錯誤 mut efi nbsp line ror 返回 調用構造

構造函數調用構造函數是會問題的.

外層函數返回的內存, 與被調用的構造函數返回的內存並不是一個內存.

錯誤示例代碼如下:

       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++構造函數調用構造函數