C++的常量

来源:互联网 发布:单词翻译软件 编辑:程序博客网 时间:2024/04/27 13:55
class A {  enum { SIZE1 = 100, SIZE2 = 200}; // 枚举常量  int array1[SIZE1];    int array2[SIZE2]; };

第一种方法,使用枚举常量

class A{  static const int SIZE=100;  int array[SIZE]; }

第二种方法,使用静态变量


注意需要和类声明中的常量比较以及和#define中定义的常量比较


class A

{

 const int size; //只能在够照函数中初始化。每个对象中的数值不一样

}


0 0
原创粉丝点击