John Lamb
Steven T. Hatton wrote:
No, I am specifically trying to initialize it at compile time. What the stupid compiler or linker is trying to do is a different story! ;) The code works if I build all the parts in the same compilation unit.
Fair enough, but look at it from the compiler's point of view. If you use a function to initialise a static const and the function is not defined in the same compilation unit, the compiler can't initialise the const at compile time. It's tricker, though I assume it's possible, to design a static linker that could do the additional compilation at link time to assign a value to the const. I think the gnu linker won't do it except, maybe, in simple cases.
I wonder if playing around with extern might work?
Did you mean to type "export". I don't think gcc handles export yet,
Not yet: markgray@soyo:/ARK/BOOKS/Thinking_in_C++/tmp> cat export.cpp export template<typename T> const T& min(const T&, const T&); export template<typename T> const T& min(const T& a, const T& b) { return (a < b) ? a : b; } int main() {} markgray@soyo:/ARK/BOOKS/Thinking_in_C++/tmp> g++ -o export.o export.cpp export.cpp:1: warning: keyword `export' not implemented, and will be ignored export.cpp:3: warning: keyword `export' not implemented, and will be ignored markgray@soyo:/ARK/BOOKS/Thinking_in_C++/tmp>