C2064 从 MSVC v100 更新到 v140 平台工具集时出现编译错误
c2064 compilation error on updating from msvc v100 to v140 platform toolset
我继承了一个必须从 MSVC 平台工具集 v100 更新到 v140 的项目。它是为了即将发布的Archicad。一切都很好,除了当我将平台工具集设置为 140 时,我的一个模板函数变得疯狂并出现编译错误:
C2064 项的计算结果不等于采用 2 个参数的函数
在此之后,我收到了同一行的警告:
类没有定义"operator()"或用户定义的转换运算符,以指向函数的指针或引用到函数,该运算符采用适当数量的参数
此块中由 IDE 指向的 return 语句:
template<typename T, typename From>
inline T Convert(From from, const std::locale& locale)
{
converters::Converter<From, T> conv;
return conv(from, locale); // <- compilation fails on this line.
}
我有几个这样的专业:
CONVERTER(API_Guid, GS::Guid, from, locale)
{
(void)locale; // It gets optimized away
return APIGuid2GSGuid(from);
}
CONVERTER
定义为:
#define CONVERTER(From, T, from, locale)
template<>
struct Converter<From, T> : public std::true_type
{
inline T operator()(const From& from, const std::locale& locale) const;
} ;
T Converter<From, T>::operator()(const From& from, const std::locale& locale) const
转换器类的operator()
重载。我已经尝试了一些解决方法,例如直接定义转换函数,但这样我就遇到了链接器错误。
有人可以指出我错过了什么吗?我使用较旧的平台工具集编译它没有问题。Microsoft在新的版本中改变了什么吗?
我已经对转换器标头进行了沙盒处理,并缩小了范围。标记了未注释无法编译的行,并抛出前面提到的编译错误 (C2064)。
这是减少的Convert.hpp:
#pragma once
#include <string>
#include "Declarations.hpp"
#include "utfcpputf8.h"
#define CONVERTER(From, T, from, locale)
template<>
struct Converter<From, T> : public std::true_type
{
inline T operator()(const From& from, const std::locale& locale) const;
} ;
T Converter<From, T>::operator()(const From& from, const std::locale& locale) const
namespace et
{
template<typename T>
inline T Convert(const wchar_t* str, const std::locale& locale = std::locale::classic())
{
std::wstring wstr(str);
return Convert<T>(wstr, locale);
}
template<typename T, typename From>
inline T Convert(From from, const std::locale& locale)
{
converters::Converter<From, T> conv;
return conv(from, locale);
}
template<typename From>
inline std::string S(const From& from)
{
return Convert<std::string>(from);
}
inline std::string S(const wchar_t* from)
{
// return Convert<std::string>(from); <- This line fails to compile on V140, but does on V100
}
namespace converters
{
template<typename From, typename T, typename _Enabler1, typename _Enabler2, typename _Enabler3>
struct Converter : _FALSETYPE_
{
};
template<typename From, typename T>
struct Converter < From, T, _IF_CONVERTIBLE_(From, T) > : _TRUETYPE_
{
inline T operator()(const From& from, const std::locale&) const
{
return (T)from;
}
};
CONVERTER(std::string, bool, from, locale)
{
(void)locale; // It gets optimized away
return et::Convert<bool>(from.c_str());
}
CONVERTER(bool, std::string, from, locale)
{
(void)locale; // It gets optimized away
return from ? std::string("true") : std::string("false");
}
CONVERTER(std::string, et::UString, s, locale)
{
(void)locale; // It gets optimized away
et::UString dest;
utf8::utf8to16(s.begin(), s.end(), std::back_inserter(dest));
return dest;
}
CONVERTER(et::UString, std::string, from, locale)
{
(void)locale; // It gets optimized away
std::string dest;
utf8::utf16to8(from.begin(), from.end(), std::back_inserter(dest));
return dest;
}
}
}
如果有人感兴趣,这里是 声明.hpp 以便于复制:
#pragma once
#include <string>
#define _TRUETYPE_ public std::true_type
#define _FALSETYPE_ public std::false_type
#define _IF_CONVERTIBLE_(From, To) typename std::enable_if<std::is_convertible<From, To>::value>::type
#define _IF_ARITHMETIC_(A) typename std::enable_if<std::is_arithmetic<A>::value>::type
#define _IF_ARITHMETIC_T_(A, T) typename std::enable_if<std::is_arithmetic<A>::value, T>::type
namespace et
{
template<typename T, typename Enabler = void, typename Blah = void>
struct IsConvertibleToString : public std::false_type
{
};
template<typename T>
struct IsConvertibleToString<T, typename std::enable_if<std::is_convertible<T, std::string>::value>::type > : public std::true_type
{
};
typedef std::u16string UString;
template<typename T, typename From>
T Convert(From from, const std::locale& locale = std::locale::classic());
template<typename From, typename T>
struct ConvertFunctor;
namespace converters
{
template<typename From, typename To, typename _Enabler1 = void, typename _Enabler2 = void, typename _Enabler3 = void>
struct Converter;
}
}
#define _IF_STRING_CONVERTIBLE_(T) typename std::enable_if<::et::IsConvertibleToString<T>::value>::type
UTF-8 CPP 可以从这里获得:链接。
我仍然对建议感兴趣,但我 95% 确定wchar_t
是 cuplrit。
我想你可能缺少一个模板<>某处...
template<>
struct Converter<From, Type> : public std::true_type
{
inline Type operator()(const From& from, const std::locale& locale) const;
};
// missing template<> here ?? As is, this is not ANSI compliant
Type Converter<From, T>::operator()(const From& from, const std::locale& locale) const { return Type(); }
相关文章:
- NPM 安装:找不到平台工具集 = v141
- 构建在VS 2013中找不到平台工具集= 'v141'
- C++ VS 工具集 141 - 142 铸造的差异
- 如果使用平台工具集构建应用,则 CCheckListBox 项在选择时会重叠'Visual Studio 2017 (v141)'
- Visual Studio Platform 工具集和运行时库
- 使用自定义工具集获取动态退出析构函数链接错误 - eh 矢量析构函数
- 在一个VS项目中使用多个工具集 - 是否存在风险
- 为什么在链接时搜索使用错误工具集的提升库?
- C2064 从 MSVC v100 更新到 v140 平台工具集时出现编译错误
- 使用类型参数专用化部分模板参数(VC++ v140 工具集)
- C V100平台工具集
- 提升链接器错误工具集
- NDK r16b 独立工具链错误:"/usr/bin/ld: this linker was not configured to use sysroots"
- 如何获取Visual Studio C++工具集标记
- 我已安装的GCC版本是我已安装的RedHat开发人员工具集的背后
- 找不到 Visual Studio 2008 的生成工具(平台工具集 = 'v90')
- 如何使用 CMake 设置 VS 平台工具集属性
- 将平台工具集更改为v140_xp时出现"Windows.h:没有此类文件或目录"错误
- Visual studio 2013项目与v120_xp工具集有MIDL 2072错误
- Visual c++ 2010 Express使用错误的工具集