编译器错误 C2492

“variable”: 具有线程存储持续时间的数据可能没有 dll 接口

该变量是使用 thread 属性和 DLL 接口声明的。 thread 变量的地址在运行时前未知,因此不能链接到 DLL 导入或导出。

下面的示例生成 C2492:

// C2492.cpp
// compile with: /c
class C {
public:
   char   ch;
};

__declspec(dllexport) __declspec(thread) C c_1;   // C2492
__declspec(thread) C c_1;   // OK