Ah, perfect. Thanks for the explanation. Brian On Fri, Apr 17, 2009 at 5:44 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > Brian Budge <brian.budge@xxxxxxxxx> writes: > >> I'm running into an issue using static const variables in my template >> class, but only with -O0. I have something like this: >> >> Bar.h >> >> template <typename Foo> >> class Bar { >> ... >> public: >> typedef uint32_t SomeType; >> static const SomeType A = 0; >> static const SomeType B = 1; >> static const SomeType C = 2; >> ... >> }; >> >> These types are used in Bar member functions, as well as by Foo (who >> knows who he is an argument for). >> >> In -O1 and above, it looks like the symbols are never generated, and >> this is fine since it's probably folded into the code. In O0, which >> I'm using for debugging, the symbols appear in my object file as 'U' >> (unresolved). > > The declaration of a const in a class is only a declaration. You also > need a definition. The current C++ standard says that the definition is > always required, but that in some cases an implementation need not > diagnose it. The new C++ standard will relax this in some cases, but > gcc does not yet implement that. > > That is, in some .cc file, you need to do > > const SomeType Bar::A; > const SomeType Bar::B; > ... > > Note that since the const was initialized in the declaration, it should > not be initialized in the definition. > > Ian >