------- Additional Comments From flash at pobox dot com  2005-08-13 04:18 
-------
Here's the discussion in our developer forum about the validity of this code; 
the rejection was originally 
reported as a bug against our compiler.

At 4:34 PM -0500 2/16/04, Stuart A. Malone wrote:
>But when I compile this kind of code using the native compiler, the 
>linker complains that Foo::kVersionNumber is an undefined symbol. 
>If I try to mollify it by placing code in my .cpp file like this:
>
> const int16_t Foo::kVersionNumber = 3;
>
>The compiler complains that the symbol has been defined twice.
>
>So how do I win?

I checked a reference manual[1] last night, which said that the 
definition should be:

const int16_t Foo::kVersionNumber;

Keep the "= 3" in the class definition, like you did before.  All 
you're doing with the above line is telling the compiler and linker 
where the storage should be defined.

-- Keith Rollin
-- Development Tools engineer

[1] "The C Programming Language", Special Edition, p. 249, section 
10.4.6.2, "Member Constants", where it says "If (and only if) you use 
an initialized member in a way that requires it to be stored as an 
object in memory, the member must be (uniquely) defined somewhere. 
The initializer may not be repeated: <example>".


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23370

Reply via email to