C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/26)
String型の配列をconstで持とうとしたら以下のエラーがでた。
class myClass {
private:
static const String errorLevels[4] = {
L"High", L"Middle", L"Low", L"Debug"
};
};
E2233 クラスメンバ変数を初期化できない
どうも以下と関係あるようだ
http://www.cplusplus.com/forum/beginner/44486/
You can only define static const integral values (i.e. short, int, long, bool, char, instance of an enum) within a struct. You can't declare static const arrays of integral values within a struct, unfortunately.
...
Since your array is so short, you might consider doing this:
struct A{
static const int m1 = 1;
static const int m2 = 3;
static const int m3 = 5;
};
配列でないのが拡張性に問題あり。
.cppで持たせることにした。
.hにconstを持つのは、API使用者に開示したい場合かもしれない。今回の場合は、別に開示したい情報でもない。
関連
cpp > クラス内での静的定数の宣言 > class MyAPI { public: static const int MAX_NAME_LENGTH; ...