zoukankan      html  css  js  c++  java
  • [development][c++] C++构造函数调用构造函数

    构造函数调用构造函数是会问题的.

    外层函数返回的内存, 与被调用的构造函数返回的内存并不是一个内存.

    错误示例代码如下:

           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

  • 相关阅读:
    MySQL 对于千万级的大表要怎么优化?
    Spring Cloud中文社区
    什么是QPS,PV
    http://www.rabbitmq.com/documentation.html
    redis
    MySQL分区表
    linux命令综合
    Python-MRO
    Python3 错误和异常
    装饰器
  • 原文地址:https://www.cnblogs.com/hugetong/p/7794942.html
Copyright © 2011-2022 走看看