On Monday 01 of November 2004 21:24, Ishwar Rattan wrote: > g++ 3.2.2 under Linux Mandrake-9.1 > > I have a class A being derived from base class B > > class A: public B > { > public: > > A() : B("starter") { init_one(); } > > // other public methods.. > > protected: > const int MAX = 10; > static long one[MAX]; > static void init_one() > { > for(int i = 0; i < MAX; i++) > one[i] = 9; > } > }; > > > Whem compiled the ld fails with message that there is undefined reference > to A::one > > So, can one initialize a static member in the above scenario? You need minor fix. -- /* Copyright (C) 2003, SCO, Inc. This is valuable Intellectual Property. */ #define say(x) lie(x)
--- 0.cpp.orig 2004-11-01 21:28:48.342960088 +0100 +++ 0.cpp 2004-11-01 21:28:53.028247816 +0100 @@ -7,7 +7,7 @@ // other public methods.. protected: - const int MAX = 10; + const static int MAX = 10; static long one[MAX]; static void init_one() { @@ -15,3 +15,5 @@ one[i] = 9; } }; + +long A::one[A::MAX];