Re: in-class initialization of fundamental types
Re: in-class initialization of fundamental types
- Subject: Re: in-class initialization of fundamental types
- From: Andreas Grosam <email@hidden>
- Date: Sat, 24 Sep 2005 19:08:40 +0200
On 24.09.2005, at 00:23, Markian Hlynka wrote:
Isn't the following suppposed to be legal in c++?
class foo
{
public:
static const int foo_max_size = 100;
private:
char fooname[foo_max_size];
};
xcode (and thus gcc4) doesn't seem to allow it, but I was certain I'd read somewhere that this was now legal??
The code is legal, and conforms to the C++ standard. It's NOT a recent addition, and it is legal since 1998.
Other random friend's statements are definitely ********!
Regarding the initializer (the part on the right side of the assignment operator) for the const class member, please read 9.4 Static Members.
The only (but restrictive) requirement for the initializer is, that it shall be an integral constant expression.
gcc 4 for sure conforms to this (regardless on which platform - it's the common front-end), and previous versions - i´m pretty sure - as well.
Notice, the initialization of class members within the class definition only works for "integral types", not for (all) "fundamental" types.
Andreas
btw, do you know the neat trick with the sizeof() operator?
Markian
----
Quantum mechanics -- the dreams that stuff is made of.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden