每种类型都有相应的字面值吗? [英] Does every type have a corresponding literal?

查看:130
本文介绍了每种类型都有相应的字面值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Bjarne Stroustrup的使用C ++的编程原理和实践(第六版,2012年11月),每种类型[ int double char string bool ]有自己的特征样式文字(p.63)。



在本书的A.2中,提到了 int (unsigned; long)和浮点文字的附加变体,以及(null)指针字面量。 / p>

每个类型都有相应的文字吗?

解决方案

Bjarne Stroustrup的使用C ++的编程原理和实践(第六版,2012年11月)指的是 ISO / IEC 14882:2003 作为相关C ++标准。在这里可以找到相关的部分,§2.13,其内容如下:

  

有几种字面量。

literal:
整数文字
字符文字
浮点文字
字符串文字
布尔文字

显然,这是一个详尽的列表;并且因为列表中可以有更多类型的文字,答案是:不,不是每个类型都有一个对应的文字。



NB对于C ++ 11,请参见 Lizusek的回答


According to Bjarne Stroustrup's Programming Principles and Practice Using C++ (Sixth Printing, November 2012), "each of [the] types [int, double, char, string, and bool] has its own characteristic style of literals" (p.63).

In §A.2 of the same book, additional varieties of int (unsigned; long) and floating-point-literals are mentioned, as well as the (null) pointer literal.

Does every type have a corresponding literal?

解决方案

Bjarne Stroustrup's Programming Principles and Practice Using C++ (Sixth Printing, November 2012) refers to ISO/IEC 14882:2003 as the relevant C++ standard. In this can be found the pertinent section, §2.13, which reads as follows:

2.13 Literals

There are several kinds of literals.

literal:
    integer-literal
    character-literal
    floating-literal
    string-literal
    boolean-literal

Apparently, this is an exhaustive list; and because there can be many more types than there are kinds of literal in that list, the answer is: no, not every type has a corresponding literal.

N.B. for the C++11 case, please see Lizusek's answer.

这篇关于每种类型都有相应的字面值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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