Re: In-class initialization of integral static const variables & Linker errors
Re: In-class initialization of integral static const variables & Linker errors
- Subject: Re: In-class initialization of integral static const variables & Linker errors
- From: Guillaume Billard <email@hidden>
- Date: Thu, 16 Jul 2009 09:47:20 +0200
Le 16 juil. 09 à 04:08, Ethan Tira-Thompson a écrit :
Trying to build this with Xcode 3.1.3 on Mac OS X 10.5.7, I get the
following linker errors:
Undefined symbols:
You are getting this because you still need to define the storage
for the statics. Sometimes this isn't necessary, and I'm not sure
why. But you can put 'int const Foo::foo; int const Bar::bar;'
somewhere in a .cpp file, and the errors should go away.
I think initializing const variables in the class declaration, if it
is allowed by the ISO standard at all, is not supported by all
compilers.
I'm pretty sure it's in the standard that 'int' statics can be
initialized within the class declaration (in the header).
However no other types can be. I'm not sure why they do that
differentiation.
-Ethan
What I don't understand is that if the main() code is replaced with
the following, it builds fine:
int i = Foo::foo;
int j = Bar::bar;
return (argc == 1) ? i : j;
I indeed defined the variables out-of-class as a fix, but I'm
interested if someone knows when this is necessary and when it's not.
_______________________________________________
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