This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: static memeber initialization in constructor??


You actually have to also define 'one' someone in your implementation
code just like you do your functions:

long A::one[MAX];

That actually causes space to be allocated for 'one'.  The declaration
just declares it (kind of like when you use 'extern' - you have to have
it actually defined someone).

Thanks,
Lyle


-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Ishwar Rattan
Sent: Monday, November 01, 2004 1:25 PM
To: gcc-help@gcc.gnu.org
Subject: static memeber initialization in constructor??

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?

-ishwar


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]