Mail Archives: djgpp/2000/01/03/14:45:31
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 -