C++ REST SDK 2.1 引入的时候报“C2766 显式专用化”,求解决方案。

2014-08-10 19:52:07 +08:00
 raincious
这是错误:

2> Http.cpp
2> ...packages\cpprestsdk.2.1.0\build\native\include\cpprest/streams.h(459): error C2766: 显式专用化;已定义“Concurrency::streams::_type_parser_integral_traits<utf16char>”
2> ...\packages\cpprestsdk.2.1.0\build\native\include\cpprest/streams.h(454) : 参见“_type_parser_integral_traits<unsigned short>”的前一个定义

这是那段代码:

判断如果是Windows,就定义两个宏
.....
#ifdef _MS_WINDOWS
#define _INT_TRAIT(_t,_low,_high) template<> struct _type_parser_integral_traits<_t>{typedef std::true_type _is_integral;typedef std::false_type _is_unsigned;static const int64_t _min = _low;static const int64_t _max = _high;};
#define _UINT_TRAIT(_t,_low,_high) template<> struct _type_parser_integral_traits<_t>{typedef std::true_type _is_integral;typedef std::true_type _is_unsigned;static const uint64_t _max = _high;};

_INT_TRAIT(char,INT8_MIN,INT8_MAX)
_INT_TRAIT(signed char,INT8_MIN,INT8_MAX)
_INT_TRAIT(short,INT16_MIN,INT16_MAX)
_INT_TRAIT(utf16char,INT16_MIN,INT16_MAX) // 这是 454 行
_INT_TRAIT(int,INT32_MIN,INT32_MAX)
_INT_TRAIT(long, LONG_MIN, LONG_MAX)
_INT_TRAIT(long long, LLONG_MIN, LLONG_MAX)
_UINT_TRAIT(unsigned char,UINT8_MIN,UINT8_MAX)
_UINT_TRAIT(unsigned short,UINT16_MIN,UINT16_MAX) // 这是 459 行
_UINT_TRAIT(unsigned int,UINT32_MIN,UINT32_MAX)
_UINT_TRAIT(unsigned long, ULONG_MIN, ULONG_MAX)
_UINT_TRAIT(unsigned long long, ULLONG_MIN, ULLONG_MAX)
#else
#define _INT_TRAIT(_t) template<> struct _type_parser_integral_traits<_t>{typedef std::true_type _is_integral;typedef std::false_type _is_unsigned;static const int64_t _min = std::numeric_limits<_t>::min();static const int64_t _max = (std::numeric_limits<_t>::max)();};
#define _UINT_TRAIT(_t) template<> struct _type_parser_integral_traits<_t>{typedef std::true_type _is_integral;typedef std::true_type _is_unsigned;static const uint64_t _max = (std::numeric_limits<_t>::max)();};

_INT_TRAIT(char)
_INT_TRAIT(signed char)
_INT_TRAIT(short)
_INT_TRAIT(utf16char)
_INT_TRAIT(int)
_INT_TRAIT(long)
_INT_TRAIT(long long)
_UINT_TRAIT(unsigned char)
_UINT_TRAIT(unsigned short)
_UINT_TRAIT(unsigned int)
_UINT_TRAIT(unsigned long)
......
1198 次点击
所在节点    C
6 条回复
heqing
2014-08-10 20:37:10 +08:00
utf16char是什么,会不会与unsigned short重复了
raincious
2014-08-10 20:38:49 +08:00
@heqing

看起来是个wchar_t。

windows_compat.h这里定义的。

typedef wchar_t utf16char;
heqing
2014-08-10 20:45:31 +08:00
再看一下wchar_t的定义
raincious
2014-08-10 20:50:59 +08:00
heqing
2014-08-10 20:56:23 +08:00
Project Properties>C/C++/Language/Treat WChar_t as Builtin type, 试试这个
raincious
2014-08-10 21:27:35 +08:00
@heqing Passed。感谢。

刚才在下curl耽搁了,好不容易下好之后立即试了这个解决方案,然后通过了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/127089

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX