Re: in-class initialization of fundamental types
Re: in-class initialization of fundamental types
- Subject: Re: in-class initialization of fundamental types
- From: Markian Hlynka <email@hidden>
- Date: Sun, 25 Sep 2005 20:07:51 -0600
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.
Hey everyone.
I'm totally confused. based on the responses here, I tried to use the initializer again, and this time it worked. I have no idea what I might have done before to make it not work! Oh well. Thanks to everyone who said it should work!! (more below... Though, the rest is more of a reply to Andreas.)
Other random friend's statements are definitely ********!
I'm guessing he wasn't paying careful attention at the time either! 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_.
I see. Section 9.4 refers to the standard, yes? Is this easily and freely available? I haven't googled C++ Standard" yet... because it seemed to me that it was likely to generate an awful lot of hits. 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.
Er... I think I knew this. What's an example of a non-integral, fundamental type, though?
btw, do you know the neat trick with the sizeof() operator?
I don't think so. You have my attention now, so do tell!
Markian
|
_______________________________________________
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