在特殊情况下,双尖括号(>)会产生语法错误 [英] Double closing angle brackets (>>) generate syntax error in SPECIFIC case

查看:172
本文介绍了在特殊情况下,双尖括号(>)会产生语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Eclipse(Luna,4.4.2)告诉我,我在以下一行上有语法错误:

Eclipse (Luna, 4.4.2) tells me that I have a syntax error on the following line:

static_cast<Vec<int, DIM>>(a.mul(b));

我记得双封闭尖括号>> 可能会导致某些编译器出现问题,因此我在两者之间加了一个空格:> > 。语法错误消失。

I remembered that double closing angle brackets >> can lead to problems with some compilers, so I put a blank in between: > >. The syntax error disappears.

但是我的程序中有很多>> ,没有检测到语法错误,例如:

BUT I have many >> in my program where no syntax error is detected, such as:

Node<Element<DIM>> * e= a.get();

为什么在上述特定情况下会出错?这与错误不是重复的:在此未声明 varName范围,因为我要特别问为什么我的编译器有时但不总是接受>>

Why do I get an error the above mentioned specific case? This is NOT a duplicate to error: 'varName' was not declared in this scope, since I'm specifically asking why my compiler does accept a >> sometimes, but not always.

推荐答案

您已使用c ++ 11之前的标准编译器。较早的标准存在一个问题,就是让解析器从 operator>中消除嵌套模板类型说明符中使用的一对闭合尖括号>> ;>()。因此,您必须在它们之间写一个空格。

You have used a pre c++11 standard compiler. The older standard had a problem letting the parser disambiguate a pair of closing angle brackets >> used in a nested template type specifier, from the operator>>(). Thus you had to write a space between them.

>>> 或<$对于旧的解析器,c $ c>>> * 处于不同的情况下,因此它们可以正常工作而不会出现错误消息。

The samples like >>> or >>* are falling under a different case for the old parsers, thus they work without error message.

我必须承认,我实际上不知道在c ++ 11(当前)标准定义中究竟做了什么,这种情况可以通过a清楚地消除。符合c ++ 11的解析器。

这篇关于在特殊情况下,双尖括号(&gt;)会产生语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆