Would I be correct in saying that there is no way to initialize a const array in a class(equivalent to above)? You can't initalize arrays in the member initialization list and you can only initialize static const inttype in the class body.Code:class xyz { const int arr[] = { 1, 2, 3, 4, 5 }; };
It seems the closest you can get is to lose the const and initialize the array manually:
This seems messy in the extreme. Any ideas?Code:class xyz { int arr[5]; public: xyz() { arr[0] = 1; arr[1] = 2; ... } };
Similarly, there seems be no way to initialize static const members, which are not integral types:
Of course, this can go outside the class without too much negative effect, but this is hardly clean.Code:class xyz { static const double d; // no way to initialize! }
Is it just me, or is C++ very messy and overly complex? There seems to be three places you can initialize member variables(depending on their types!) and still, as far as I can tell, there are variable types that can not be cleanly initialized!



LinkBack URL
About LinkBacks


