How do I define an in-class constant?

原文翻译如下:

一般来说如果你要定义一个数据的大小,在类里面你可以这么做:

class X {
	static const int c1 = 7;
	enum { c2 = 19 };

	char v1[c1];
	char v2[c2];

	// ...
};

static const只能用于interger和枚举,如果你要使用它,必须以常量的形式。

以上并没有定义变量,所以你不能取地址。

主要是为了方便。。

参考:http://www.stroustrup.com/bs_faq2.html#in-class

猜你喜欢

转载自www.cnblogs.com/rongminglu/p/12921146.html
今日推荐