RE: static memeber initialization in constructor??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] On
Behalf Of Ishwar Rattan
Sent: Monday, November 01, 2004 1:25 PM
To: gcc-help@xxxxxxxxxxx
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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux