When using std :: basic_stringstream <char16_t> in VC ++ 14
I am trying to do some processing on baic char16_t ( u16string ) and have u16string into some problems. This short program:
#include <string> #include <sstream> int main() { int foo = 65; std::basic_stringstream<char16_t> ss; ss << foo; std::u16string s = ss.str(); } Generates an error:
Error C2491 'std::numpunct<_Elem>::id': definition of dllimport static data member not allowed. xlocnum 259 I tried this on some online compilers, but there is no error.
Thanks for any help I can get!
OK, this seems like an error in the standard VC ++ libraries or the VC ++ compiler, or perhaps even both.
<xlocnum>, line 85, is declared within class numpunct :
__PURE_APPDOMAIN_GLOBAL _CRTIMP2_PURE static locale::id id; // unique facet id <xlocnum>, line 258/259 defines:
template<class _Elem> __PURE_APPDOMAIN_GLOBAL locale::id numpunct<_Elem>::id; _CRTIMP2_PURE defined as _CRTIMP2 , which in turn is defined as __declspec(dllimport) .
Now, according to my reading of VC ++ docs, this should be fine. __declspec(dllimport) allowed for static declarations. However, this is not allowed with static definitions. But the definition does not have __declspec(dllimport) , only the declaration does.
However, an error occurs: the compiler sees the definition, treating it as if it is __declspec(dllimport) , and creates an error.
The reason I'm not sure if this is a compiler error or a library error is because the compiler also issues a warning to complain that the declaration and definition do not match - this is one __declspec(dllimport) and the other is not . Since the definition cannot, according to the documentation, be __declspec(dllimport) , this tells me that neither the declaration nor the definition should be __declspec(dllimport) .
If we look at other similar members, this suspicion will be confirmed. For example, num_get::id not _CRTIMP2_PURE , nor is num_put::id .
So, I think two possibilities. One of them is that _CRTIMP2_PURE is an error and should be deleted. Another is that the compiler gives an erroneous diagnosis when it claims to define __declspec(dllimport) when it is not.
In any case, I think the sample code should compile, and this is what Microsoft will need to fix.