如何声明线程本地的静态类数据成员?

问题描述

我一直在用 C++(11) 做一个学习项目,我想实现一些类似于 -

class ImpClass
{
    static __thread Foo foo;

    void doSomething()
    {
        ImpClass::foo.doSomeOtherThing();
        // do something;
    }
};

但将此结果编译为 undefined reference to 'ImpClass::foo[abi:cxx11]'

当使用 thread_local 而不是 __thread 时,它会显示 undefined reference to 'TLS init function for ImpClass::foo[abi:cxx11]'

我使用的是 gcc 编译器(版本:9.3.0)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)