什么是在<:语法C中的意义是什么? [英] What is the significance of the <: syntax in C?

查看:432
本文介绍了什么是在<:语法C中的意义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  &LT ;:不能开始模板参数列表

你知道吗,

int a<:10:>;

等同于

int a[10];

我写了一些片code,在那里我有一个全局命名空间和空间的限制,说NS1现在的。我在我的全局命名空间中的一类叫做模块和I导入NS1其他一些库,其中有一个叫模块太类。我试图创建我的模块,即在:: NS1函数内,这样模块一个std ::名单,我得到这个编译错误

I was writing some piece of code, where in I have a global namespace and a restricted namespace, say NS1 for now. I have a class called Module in my global namespace and I import some other libraries in NS1, which have a class called Module too. I was trying to create a std::list of my Module, i.e. ::Module inside a function in NS1 and doing so, I got this compilation error

std::list<::Module*> &myModule;

genllvm.cpp:60:11: error: ‘<::’ cannot begin a template-argument list
./genllvm.cpp:60:11: note: ‘<:’ is an alternate spelling for ‘[’. Insert whitespace between ‘<’ and ‘::’
./genllvm.cpp:60:11: note: (if you use ‘-fpermissive’ G++ 

这是什么&LT;:语法的意义是什么?

What is the significance of this "<:" syntax?

推荐答案

其呼叫替代标记。 c + +有几个人:

Its call alternative tokens. C++ have several of them:

 <%     {
 %>     }
 <:     [
 :>     ]
 %:     #
 %:%:   ##
 and    &&
 bitor  |
 or     ||
 xor    ˆ
 compl  ~
 bitand &
 and_eq &=
 or_eq  |=
 xor_eq ˆ=
 not    !
 not_eq !=

您可以看到一些替代令牌由字母。所以,你可以写如果(A&LT; B和B c为C)在编译器能正确处理它们。他们的存在是缺乏键盘或字符集的符号。替代令牌从未与主之一(不像三字母)取代,但它们具有相同的行为作为主之一

You can seen some of the alternative token consists of letters. So you can write if (a<b and b<c) in a compiler which can correctly handle them. Their existence is for lack of symbols in keyboards or character sets. The alternative tokens are never replaced with the primary one (unlike trigraphs), but them behave the same as the primary one.

不过,C ++ 0x中需要进行特殊处理&LT; :: (2.5p3):

However, C++0x require special treatment for <:: (2.5p3):

否则,如果接下来的三个字符与所述; ::和随后的
  人物既不是:也不是>,在&lt;被视为一个preprocessor令牌
  本身,而不是作为替代令牌所述的第一个字符;:

Otherwise, if the next three characters are <:: and the subsequent character is neither : nor >, the < is treated as a preprocessor token by itself and not as the first character of the alternative token <:.

SomeTemplate&LT; :: SomeClass的方式&gt; 可正确处理

这篇关于什么是在&lt;:语法C中的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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