C2491:“std::numpunct<_Elem>::id":不允许定义 dllimport 静态数据成员 [英] C2491: 'std::numpunct<_Elem>::id' : definition of dllimport static data member not allowed
问题描述
给定以下代码,
#include <sstream>
#include <stdint.h>
template <typename D> void func() {
std::basic_stringstream<D> outStream;
D suffix = 0;
outStream << suffix;
}
void main() {
func<char>(); // OK
func<wchar_t>(); // OK
func<uint16_t>(); // generates C2491
}
以下编译错误是什么意思?
what does following compile error mean?
错误 C2491:'std::numpunct<_Elem>::id':不允许定义 dllimport 静态数据成员
error C2491: 'std::numpunct<_Elem>::id' : definition of dllimport static data member not allowed
推荐答案
你不能用
_declspec(dllimport)
并为它们提供定义.
限定符告诉编译器该函数是从与您现在正在编译的库不同的库中导入的,因此为其提供定义是没有意义的.
The qualifier tells the compiler that the function is imported from a different library than the one you are compiling now, so it wouldn't make sense to provide a definition for it.
当包含标题时,限定符应该是
When including the header, the qualifier should be
_declspec(dllimport)
当你编译提供方法定义的模块时,它应该是:
and when you are compiling the module that provides a definition for the method it should be:
_declspec(dllexport)
通常的做法是:
#ifdef CURRENT_MODULE
#define DLLIMPORTEXPORT _declspec(dllexport)
#else
#define DLLIMPORTEXPORT _declspec(dllimport)
#endif
define CURRENT_MODULE
仅在包含定义的模块中定义,因此在编译该模块时会导出该方法.包含标题的所有其他模块都没有定义 CURRENT_MODULE
,该函数将被导入.
The define CURRENT_MODULE
is only defined in the module that contains the definitions, so when compiling that module the method is exported. All other modules that include the header don't have CURRENT_MODULE
defined and the function will be imported.
我猜您的指令 - _declspecimport
- 与此类似.
I'm guessing your directive - _declspecimport
- is similar to this.
这篇关于C2491:“std::numpunct<_Elem>::id":不允许定义 dllimport 静态数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!