C2491: 'std::numpunct<_elem>::id' : 不允许定义 dllimport 静态数据成员
给出以下代码,
#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
}
以下编译错误意味着什么?
错误 C2491:“std::numpunct<_Elem>::id”:不允许定义 dllimport 静态数据成员
Given following code,
#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?
error C2491: 'std::numpunct<_Elem>::id' : definition of dllimport static data member not allowed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能声明方法
并为其提供定义。
限定符告诉编译器该函数是从与您现在正在编译的库不同的库导入的,因此为其提供定义是没有意义的。
当包含标头时,限定符应该是
,并且当您编译提供方法定义的模块时,它应该是:
通常的方法是:
定义
CURRENT_MODULE
仅在包含定义的模块,因此在编译该模块时会导出该方法。包含标头的所有其他模块均未定义CURRENT_MODULE
,并且将导入该函数。我猜你的指令 -
_declspecimport
- 与此类似。You can't declare methods with
and provide a definition for them.
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
and when you are compiling the module that provides a definition for the method it should be:
The usual way of doing this is:
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 haveCURRENT_MODULE
defined and the function will be imported.I'm guessing your directive -
_declspecimport
- is similar to this.