类常量
来源:互联网 发布:永久免费域名 编辑:程序博客网 时间:2024/06/03 11:27
C++标准允许在类的定义中定义静态整数常量,但其他类型的类常量则需要单独的定义或将常量封装在函数中。举例:
// File widget.h
class Widget {
static const int defaultWidth= 400; // value provided indeclaration
static const doubledefaultPercent; // value providedin definition
static const char* Name(){return "Widget"; }
};
// File widget.cpp
const double Widget::defaultPercent = 66.67; // value provided indefinition
const int Widget::defaultWidth; // definition required
此外,enum也常用于定于类常量。对于单独的类常量,static声明是必须的,这样才能保证所有的类常量公用一个地址空间。
- 常量类
- 类常量
- 类常量
- 类常量
- 普通常量和类常量字段
- 常量接口 vs 枚举常量类
- 常量接口 vs 枚举常量类
- php常量--自定义/系统/类常量
- PHP中的自定义常量与类常量
- php之魔术常量、类常量
- PHP中的自定义常量与类常量
- 常量接口 vs 枚举常量类
- 用类创建常量
- Liferay 中的常量类
- 类的常量
- 类中的常量
- java类字面常量
- C++类中的常量
- 隐式类型转换与转换操作符operatorT
- C++输出N位水仙花数
- 菜鸟程序员成就达成
- 避免使用宏
- H264--Intel硬编码
- 类常量
- C++定义类对圆做运算
- 具有链接的C++实体
- 设计模式-builder(构造器模式)
- 374. Seeing is beleving. 眼见为实
- jQuery实现滑动效果
- 排序算法
- 对待拷贝构造函数和赋值函数有3种境界
- archlinux升级pacman