zoukankan      html  css  js  c++  java
  • c++ 静态变量

    You will need to define the static variable, even if it is not initialized explicitly. That is what is missing in your code. You should have provided a simple example to reproduce the issue, but for your convenience I am providing one which works.

    main.cpp

    class Foo {
        public:
            static int si;
            static void bar();
    };
    
    int Foo::si = 0; // By default, it will be initialized to zero though.
    
    void Foo::bar() {
         Foo::si = 10;
    };
    
    int main()
    {
        Foo::bar();
        return 0;
    }


    ===================================================================

    The correct code is (.cpp):

    #include "rtnamedinstance.h"
    
    // Initialize static members
    int RtNamedInstance::_nextInstanceNumber = 0;
    QMutex RtNamedInstance::_syncObj(QMutex::Recursive);
    
    RtNamedInstance::RtNamedInstance(QString instanceName)
    {
        QMutexLocker locker(&_syncObj);
    
        // [... other code here ...]
    }
  • 相关阅读:
    react脚手架
    快速创建一个node后台管理系统
    vue脚手架结构及vue-router路由配置
    Spring 事务管理-只记录xml部分
    Spring-aspectJ
    Maven 自定义Maven插件
    JVM
    JVM
    Spring
    Digester
  • 原文地址:https://www.cnblogs.com/liujx2019/p/10315434.html
Copyright © 2011-2022 走看看