From: pavenis AT lanet DOT lv Message-ID: To: Adam Maj , djgpp AT delorie DOT com Date: Mon, 3 Jan 2000 19:48:17 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: problem using "templates" In-reply-to: <386B409A.2432FDEE@ifj.edu.pl> X-mailer: Pegasus Mail for Win32 (v3.12b) Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On 30 Dec 99, at 12:23, Adam Maj wrote: > Hi, > > I have serious problem, connected with using " templates" in DJGPP. I > cannot use objects "static", because this leads to errors. > Here is small example of program "TEST. CC", that is causing errors: > > #include > template class my_class { > public : > static char* str; > }; > template char* my_class::str="abc"; > main() { > cerr << my_class::str << endl; > } > Reproduced with gcc-2.95.2. Possible workaround: gcc -c -frepo -O2 test.cc gcc -frepo test.o -lstdcxx -o test.exe However I cannot say how it will work in more complicated source (At least it works with this example). One more possible workaround: class my_class_base { public : static char* str; }; char* my_class_base::str="abc"; template class my_class : public my_class_base { }; I understand it looks ugly, but it should work. Andris > > Here is announcement of error (from window "Message Window" in RHIDE) : > Compiling: test.cc > no errors > Creating: test.exe > Error: test.o: In function `main': > test.cc(1) Error: undefined reference to `my_class::str' > There were some errors > > If we will exchange declaration of variable type of variable " str" > from" char*" into" int" program will work (and compile oneself) well. > But I think that use of type" int" : is the only exception, when it is > possible to use static variable in "template". In remaining situations > program does not compile oneself, or works incorrect (when I use type" > long long int" program work, but returns unsuitable value of variable > "str"). > > How can I fix this bug ? Maybe there is (or will be) new version of GNU > (or DJGPP) ? > I am using version 202 > If You can help, please answer. > > Thanks a lot > Rafal Maj > > >