我需要一些帮助来理解为什么下面的代码无法在VC2012上编译但在VC2013中编译得很好?有没有办法让它在VC2012上运行,因为那是我们的构建系统可用的编译器?
编译器版本是:
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50806 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
此时模板尚未实例化 - 它纯粹是导致错误的模板本身的编译。该行生成错误:
`typedef typename Traits::return_type return_type;` errors in directory d:\tests d:\ tests\main.cpp(34) : error C2146: syntax error : missing ';' before identifier 'return_type' error-continuation d:\tests\main.cpp(35) : see reference to class template instantiation 'Traits' being compiled d:\ \tests\main.cpp(34) : error C2868: 'Traits::return_type' : illegal syntax for using-declaration; expected qualified-name
template<typename Functor>
struct Traits
{
enum { Color = 1 };
typedef decltype(&Functor::operator()) CallOperatorType;
typedef typename Traits<CallOperatorType>::return_type return_type;
};
template<typename Ret, typename Functor, typename Arg0>
struct Traits<Ret(Functor::*)(Arg0)>
{
enum { Color = 2 };
typedef Ret return_type;
};
template<typename Ret, typename Arg0>
struct Traits<Ret (*)(Arg0)>
{
enum { Color = 3 };
typedef Ret return_type;
};