Message-ID: <397BC997.9C504DD9@puckbell.net> From: Tasci Synx X-Mailer: Mozilla 4.73 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Enabling Static Data in Templates Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 65 Date: Sun, 23 Jul 2000 21:44:07 -0700 NNTP-Posting-Host: 63.197.122.98 X-Complaints-To: abuse AT pacbell DOT net X-Trace: news.pacbell.net 964413410 63.197.122.98 (Sun, 23 Jul 2000 21:36:50 PDT) NNTP-Posting-Date: Sun, 23 Jul 2000 21:36:50 PDT Organization: SBC Internet Services To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com This might be a problem with djgpp, so I wanted to ask here. The Ansi C++ standard gives an example of a static data member in a templated class: --------------------------------------------------------- template class X { static T s; }; template T X::s = 0; --------------------------------------------------------- However, upon putting such a thing in a header file, I received a linker error. test.o: In function `foo::blech(void)': test.cpp:15: undefined reference to `foo::bar' collect2: ld returned 1 exit status Here is the test code I compiled: --------------------------------------------------------- // in test.h #include using std::cout; template struct foo { static Type bar; static void blech(void); }; template Type foo::bar = 33; template inline void foo::blech(void) { cout << "Pass the bar:" << bar << endl; } --------------------------------------------------------- --------------------------------------------------------- // in test.cpp #include "test.h" void main(void) { foo test; test.blech(); } --------------------------------------------------------- Is this a problem specific to djgpp? Is there a switch I can use to make sure my static templated data members are created properly? Thank you. Tasci -- Stories 'n stuff: http://velar.ctrl-c.liu.se/vcl/Authors/Starling/ To send me an email, just replace the @ and the . -----wassdamo at pacbell dot net