delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/03/14:45:31

From: pavenis AT lanet DOT lv
Message-ID: <B0000114459@stargate.astr.lu.lv>
To: Adam Maj <Adam DOT Maj AT ifj DOT edu DOT pl>, djgpp AT delorie DOT com
Date: Mon, 3 Jan 2000 19:48:17 +0200
MIME-Version: 1.0
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

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 <iostream.h>
>       template <class ccc> class my_class {
>       public :
>       static char* str;
>       };
>       template <class ccc> char* my_class<ccc>::str="abc";
>       main() {
>       cerr << my_class<int>::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 ccc> 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<int>::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
> 
> 
> 


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019