C ++ crazy typedef:标准允许这种语法的意义是什么? [英] C++ crazy typedef : what is the point of allowing this syntax by the Standard?

查看:156
本文介绍了C ++ crazy typedef:标准允许这种语法的意义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

旧的熟悉的:

typedef int cute_int; //cute : common and familiar syntax. 

此语法是完美的。没问题。

This syntax is perfect. No problem.

现在,当我们可以写如上所述的typedef时,那么允许这种语法的意义是什么:

Now, when we can write typedefs like above, then what is the point of allowing this syntax:

int typedef crazy_int; //crazy : uncommon and unfamiliar syntax.

只是为了混淆程序员?这个语法甚至在任何地方都需要的(事实上我们有前一个)?从编译器的角度来看,你觉得怎么样?他们觉得它可爱还是疯狂?

Just to confuse programmers? Is this syntax even needed anywhere (when in fact we've the previous one)? What do you think from the compilers' point of view? Do they find it cute or crazy? Or it doesn't matter to the compilers at all?

顺便说一句,这段代码来自这里:
使用typename和typedef的typename关键字< a>

By the way, this code came from here : Use of typename keyword with typedef and new

如果您想知道这是否是语法错误,请查看

In case if you're wondering if that is syntax error, then check out the working code here at ideone.

推荐答案

这里的另一面是你必须处理旧的错误和兼容性问题。例如,我认为C声明语法一个失败的实验,然而,我采用它为C ++。我认为当时的替代和改进不会有改进的问题,我率是一个小问题,更严重的问题是保持语言定义的接近C演变。 - Bjarne Stroustrup

"The flip side of this is that you have to deal with old mistakes and with compatibility problems. For example, I consider the C declarator syntax an experiment that failed. Nevertheless, I adopted it for C++. The alternatives and improvements I considered at the time would not have improved matters. I rate is as a minor problem. The more serious problem is to maintain closeness of language definitions as C evolves." - Bjarne Stroustrup

这篇关于C ++ crazy typedef:标准允许这种语法的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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