- Eric
On Thu, Jul 16, 2009 at 2:47 AM, Guillaume Billard<
email@hidden> wrote:
>
> 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.