【C++基础学习】《C++ Primer》中的“有序型”

本人在看《C++ Primer(第三版)》中文版看到类一章时,遇到了“有序型”这个概念。(Page527)

原文摘录如下:

作为特例,有序型的const静态数据成员可以在类体中用一常量值初始化。例如,如果决定用一个字符数组而不是string来存储账户的姓名,那么我们可以用int型的const数据成员指定数组的长度。例如:

//头文件 class Account{ //... private: static const int namesize = 16; static const char name[namesize]; }; //文本文件 const int Account::namesize;//必须的成员定义 const char Account::name[namesize] = "Savings Account";


因为name是一个数组(不是有序类型),所以它不能在类体内被初始化。任何试图这么做的行为都将导致编译错误。例如:

//头文件 class Account{ //... private: static const int namesize = 16;//OK:有序类型 static const char name[namesize] = "Savings Account";//错误 };


那么这里所说的“有序类型”到底是什么呢?

我查了一下英文原版,它原版上是:integral type。

又在网上查了查,发现这个地方应该指的是“整值类型”。指char、short、int、long和它们的unsigned版本,不含float和double。

Google一下integral type可以搜索到一些资料。

这是从IBM网站上的内容:

Integral types
Integer types fall into the following categories:
Signed integer types:
signed char
short int
int
long int
long long int
Unsigned integer types:
unsigned char
unsigned short int
unsigned int
unsigned long int
unsigned long long int
The unsigned prefix indicates that the object is a nonnegative integer. Each unsigned type provides the same size storage as its signed equivalent. For example, int reserves the same storage as unsigned int. Because a signed type reserves a sign bit, an unsigned type can hold a larger positive integer value than the equivalent signed type.


一些翻译过来的书籍有些地方翻译得不好还真是伤不起。看来最好还是阅读英文原版的书籍~~~


转载于:https://www.cnblogs.com/xiajun/archive/2011/11/10/2298631.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值