• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: in-class initialization of fundamental types
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: in-class initialization of fundamental types
      • From: Markian Hlynka <email@hidden>
References: 
 >in-class initialization of fundamental types (From: Markian Hlynka <email@hidden>)

  • Prev by Date: Re: Specifying "enum" data size
  • Next by Date: Re: error: stray '\177' in program
  • Previous by thread: Re: in-class initialization of fundamental types
  • Next by thread: Re: in-class initialization of fundamental types
  • Index(es):
    • Date
    • Thread