zoukankan      html  css  js  c++  java
  • C++ 使用成员初始化列表的一个小坑

    注意在成员列表中初始化的顺序并不是列表顺序 而是:

    • 在类中声明的顺序!
    EventLoop::EventLoop() :looping(false), quit(false),_tid(curThreadId()), poller(new Poller(this)){//, timerQueue(new TimerQueue(this)) {
    	std::cout<<_tid<<std::endl;
    	if (t_LoopInThisThread) {
    //		LOG_FATAL << "Another EventLoop " << t_LoopInThisThread << " Exists in this Thread " << _tid;
    	}
    	else {
    		t_LoopInThisThread = this;
    	}
    }
    
    
    

    初始化顺序是由

    private:
    		typedef std::vector<Channel*> ChannelVec;
    		std::unique_ptr<Poller> poller;
    		std::unique_ptr<TimerQueue> timerQueue;
    		Timestamp pollReturnTime;
    		ChannelVec activeChannels; 
    		ThreadId _tid;
    		bool looping;
    		bool quit;
    
    

    这里决定的。。。

    在成员初始化列表中有前后顺序依赖的时候一定要注意!

  • 相关阅读:
    linux 文件类型 文件权限
    微信公众号支付
    struts2 详解
    git 命令行操作
    javascript 闭包
    SVN 基本操作
    javascript 函数 方法
    git
    javascript变量 数组 对象
    Intellij调试debug
  • 原文地址:https://www.cnblogs.com/joeylee97/p/8931988.html
Copyright © 2011-2022 走看看