c++/6945: A static constant that is initialize inline is not create if only a temperary is used

Phil Edwards phil@jaj.com
Fri Jun 7 14:53:00 GMT 2002


On Fri, Jun 07, 2002 at 05:27:50PM -0400, spamjunk wrote:
> Not true.  You can't do that when its initialized inline in the class, the
> compiler will tell its that its defined twice.

Incorrect; writing

    class Foo
    {
        static const int foo = 42;
    };

only provides a handy way of keeping the '42' in the header file.  It does
not provide a definition, only a declaration.  Writing the above only means
that in the ".cc" file, you can write

    const int Foo::foo;

instead of 

    const int Foo::foo = 42;

You should either find more textbooks on C++, or buy a copy of the standard.
(At $18 for a PDF it's pretty cheap, although the reading is dry.)


Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams



More information about the Gcc-bugs mailing list