Compile error for (char based) STL (stream) containers in Visual Studio

后端 未结 2 1000

This is basically the same question as [SO]: C2491: \'std::numpunct<_Elem>::id\' : definition of dllimport static data member not allowed [closed], but considering the follow

2条回答
  •  悲&欢浪女
    2021-01-21 10:01

    The problem occurs because in the templated class std::numpunct, the public variable id is declared with _CRTIMP2_PURE_IMPORT. I haven't chased down the definition of this, but it presumably sets this variable to be imported from the C runtime dll.

    The way to fix the problem is to specialize the std::numpunct class for the character type you wish to use, but declare the id variable without _CRTIMP2_PURE_IMPORT.

    As the OP refers to a now out of date version of Visual Studio, I won't try and reference specific files or line numbers, as they may change from version to version. I also won't provide a specific specialization that can be used, as this probably depends upon exactly what the OP wants (it may be easy if they wish to just use their locale, or a bit more difficult if they wish to use other/any locale).

提交回复
热议问题