------- Comment #3 from Bernd dot Donner at gmx dot net 2008-05-19 00:00 ------- (In reply to comment #2) > In other terms, just add, after the declaration of struct A: > > const int A::N; >
According to the C++ standard "static const" member variables can be declarend _and_ defined immediately inside the declaration of the class. It should not be neccessary to declare A::N outside the class again. Other compilers "microsoft express 2005" by the way do accept this code. The definition of A::N is present. Otherwise, why does this code compile and link fine? This program is accepted by gcc: #include <iostream> #include <algorithm> struct A { static const int N = 2; }; int main () { std::cout << "Number: " << A::N << "\n"; } This program is _not_ accepted by gcc: #include <iostream> #include <algorithm> struct A { static const int N = 2; }; int main () { std::cout << "Number: " << std::min(1, A::N) << "\n"; } Static const member variables may be defined and declared the way I have proposed. According to the standard it is no more neccessary to provide a declaration outside the class, I know that this was once neccessary. The web is full of examples that shows that my declaration and definition of A::N is legal in C++. Sorry, for insisting to look at this problem once again. -- Bernd dot Donner at gmx dot net changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36261