简体   繁体   English

错误<ratio>和<memory>从vs2013升级到vs2017后

[英]error in <ratio> and <memory> after upgrading from vs2013 to vs2017

I recently upgraded to Visual Studio 2017 and now I get a syntax error in from standard library.我最近升级到 Visual Studio 2017,现在我从标准库中收到语法错误。

This is the output:这是输出:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\ratio(220): error C2947: expecting '>' to terminate template-argument-list, found '<' 
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\ratio(221): error C2226: syntax error: unexpected type 'std::integral_constant<_Ty,_Val>::type' 
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\ratio(221): error C2988: unrecognizable template declaration/definition
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\ratio(221): error C2059: syntax error: ',' 

This is where it happens:这是它发生的地方:

template<class _R1,
    class _R2,
    bool _Sfinae>
    struct _Ratio_multiply_sfinae<_R1, _R2, _Sfinae, void_t<
        typename _Ratio_multiply<_R1, _R2>::_Num::type,
        typename _Ratio_multiply<_R1, _R2>::_Den::type>>
    {   // typename ratio<>::type is unnecessary here
    typedef ratio<
        _Ratio_multiply<_R1, _R2>::_Num::value,
        _Ratio_multiply<_R1, _R2>::_Den::value> type;
    };

My guess is that somehow the compiler thinks >> is an operator, but I can't edit it to > > for testing purposes.我的猜测是编译器以某种方式认为>>是一个运算符,但我无法将其编辑为> >以进行测试。

I haven't included <ratio> but I think it is used for <chrono> and therefore <mutex> .我没有包含<ratio>但我认为它用于<chrono> ,因此用于<mutex>

Update:更新:

I just realized that during compilation, InteliSense complains about that place, but before and after compiling it doesn't complain about it.我刚刚意识到,在编译期间,InteliSense 会抱怨那个地方,但是在编译之前和之后它并没有抱怨它。 Somehow it seems the compiler setting have been changed, but how I don't know.不知何故,似乎编译器设置已更改,但我不知道。 The other question is why did it work with vs2013.另一个问题是为什么它适用于 vs2013。

I think the standard changed between C++03 and C++11 to address the issue you mentioned about "> >" vs ">>"我认为标准在 C++03 和 C++11 之间发生了变化,以解决您提到的有关“>>”与“>>”的问题

You might need to switch compiler versions.您可能需要切换编译器版本。

This is an old topic.这是一个老话题。 But I recently faced a very similar issue.但我最近遇到了一个非常相似的问题。 The root cause was that somewhere in the code there was a define like根本原因是代码中的某个地方有一个像

#define void_t void

which provoked the compiler errors.这引发了编译器错误。 Turning it to typedef helped.将其转换为 typedef 有帮助。

As you can see void_t is used in the definition of _Ratio_multiply_sfinae and is also defined in the <ratio> as a templated structure.正如你可以看到void_t在的定义中使用_Ratio_multiply_sfinae并且也是在定义<ratio>作为模板结构。 The define above messed up everything.上面的定义搞砸了一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM