Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从msvc v100更新到v140平台工具集时发生c2064编译错误_C++_Templates_Visual C++_Visual Studio 2015_Macros - Fatal编程技术网

C++ 从msvc v100更新到v140平台工具集时发生c2064编译错误

C++ 从msvc v100更新到v140平台工具集时发生c2064编译错误,c++,templates,visual-c++,visual-studio-2015,macros,C++,Templates,Visual C++,Visual Studio 2015,Macros,我继承了一个项目,该项目必须从MSVC平台工具集v100更新到v140。这是为即将发布的Archicad。一切都很好,但当我将平台工具集设置为140时,我的一个模板函数失控并出现编译错误: C2064项不计算为具有2个参数的函数 就在这之后,我收到了一条警告: 类未定义“运算符()”或用户定义的转换运算符,该运算符指向具有适当数量参数的函数指针或函数引用 此块中IDE指向的return语句: template<typename T, typename From> inline T C

我继承了一个项目,该项目必须从MSVC平台工具集v100更新到v140。这是为即将发布的Archicad。一切都很好,但当我将平台工具集设置为140时,我的一个模板函数失控并出现编译错误:

C2064项不计算为具有2个参数的函数

就在这之后,我收到了一条警告:

类未定义“运算符()”或用户定义的转换运算符,该运算符指向具有适当数量参数的函数指针或函数引用

此块中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.
}
转换器
定义为:

#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
这是Declarations.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
#pragma一次
#包括
#定义TRUETYPE\uPublic std::true\uType
#定义FALSETYPE\uPublic std::FALSETYPE
#定义可转换类型名称std::启用类型

#define_IF_算术(A)typename std::enable_IF我想你可能在某处缺少一个模板

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(); }
模板
结构转换器:公共std::true\u类型
{
内联类型运算符()(const From&From,const std::locale&locale)const;
};
//这里缺少模板??实际上,这不符合ANSI标准
类型转换器::运算符()(const From和From,const std::locale和locale)const{return Type();}

您能在问题中标出这些警告的代码行吗?如果你能准备一份表格,那将很有帮助。另外,请花一些时间阅读,特别是名为“”和“”的章节。也请阅读。如果您打算继续工作这么久,各方都会从中受益。MS正在努力使其编译器更接近ANSI标准。自VC6以来,编译器的每一个版本都有一小部分他们称之为“破坏性更改”,这使它们更接近这一目标。@ArturR.Czechowski我已经标出了编译失败的确切路线。我知道将VC 6视为不符合标准是很酷的,但整部分都有点愚蠢,考虑到VC 6是在C++98标准化之前发布的。是的,微软正试图提高其编译器的标准遵从性,就像所有其他供应商一样。这也是我发现的第一件事,但我对这个答案有几个问题。首先,您没有真正解释缺少的
模板
在他的代码中的位置。问题在于
转换器
宏的定义;也许你应该在某个地方提一下,让答案更清楚?第二,您实际上还没有测试过它以确认它确实是答案,所以我觉得在评论中提出这种建议更合适。我已经在您指出的地方添加了可能缺少的模板,带有
}\模板类型转换器也做了一些研究,在文章中引用了C++模板的引用,它指出对于类的专业化,任何成员函数的定义必须定义为“普通”成员函数。我的代码是这样的。我注意到了一些东西。inline关键字应该位于函数实现的前面。我错了。删除模板。正如这里所指出的:当试图直接定义转换函数时,内联的位置可能是链接错误的来源?
#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
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(); }