c++ : problem using static data members

From: patrick carosso (carossopatrick_at_yahoo.it)
Date: 10/29/04


Date: Fri, 29 Oct 2004 18:12:20 GMT

Hello,
I want all Dummy class instances share the same data member,
but I can't compile the following:

class Dummy
{
public:
Dummy() {};
~Dummy() {};
static int a;
};
int main(void)
{
Dummy D;
D.a=10;
Dummy::a=10;
return 0;
}

gcc 3.3.4 (run with no flags) says:

/tmp/ccoKOlNt.o(.text+0x1d): In function `main':
: undefined reference to `Dummy::a'
/tmp/ccoKOlNt.o(.text+0x27): In function `main':
: undefined reference to `Dummy::a'
collect2: ld returned 1 exit status

Probably I've not understood what static members are...
Thank!


Quantcast