From: "Rafal Maj" Newsgroups: comp.os.msdos.djgpp Subject: Odp: static Date: Thu, 3 May 2001 17:24:37 +0200 Organization: Academic Computer Center CYFRONET AGH Lines: 52 Message-ID: <9cs1p8$a0d$1@info.cyf-kr.edu.pl> References: <9cre3n$4bq$1 AT info DOT cyf-kr DOT edu DOT pl> NNTP-Posting-Host: d-94-53-28.cyfronet.krakow.pl X-Trace: info.cyf-kr.edu.pl 988908137 10253 149.156.1.188 (3 May 2001 16:42:17 GMT) X-Complaints-To: news AT cyf-kr DOT edu DOT pl NNTP-Posting-Date: Thu, 3 May 2001 16:42:17 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com After short lecture of "Symphony of C++" I realise, that I just forgot to put declaration of my static variable outside class definition ;). But, ther still is small bug in DJGPP : my first example - with missing declaration outside class and with function body inside class - is compiling without any errors or warnings ?! class cA { public : static int a; public : static void f(); }; int cA::a; // <- :) void cA::f() { a=3; } int main() { } Użytkownik Rafal Maj w wiadomości do grup dyskusyjnych napisał:9cre3n$4bq$1 AT info DOT cyf-kr DOT edu DOT pl... > (Please, I need to get answer fast - if You can help me) > I didn't use static for long time, so I have totaly forgoten how to use it > :-( > > Why this code : > class cA { > private : static int a; > public : static void f(); > }; > void cA::f() { a=3; } > int main() { } > gives me this error message : > Creating: a.exe > Error: a.o: In function `cA::f(void)': > Error: a.cc(.text+0x5): undefined reference to `cA::a' > Error: collect2: ld returned 1 exit status > Why after moving body of static function inside class definition everything > is allright : > class cA { > private : static int a; > public : static void f() { a=3; }; // ok > }; > // void cA::f() { a=3; } - error > int main() { } > > How to write this small example correct ? I must have funciton body outside > of class definition, because I want this class to be splited into .cc and .h > > Thanks in advice.... > >