Mail Archives: djgpp/1998/04/17/03:02:25
From: | schuster AT eev DOT e-technik DOT uni-erlangen DOT de
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | C++ templates question
|
Date: | Fri, 17 Apr 1998 07:00:15 GMT
|
Organization: | Regionales Rechenzentrum Erlangen, Germany
|
Lines: | 80
|
Message-ID: | <19980417.7001502@seneca>
|
NNTP-Posting-Host: | eev6.e-technik.uni-erlangen.de
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hi !
When writing some C++ code with djgpp, i've encountered the following
problem with templates (I don't know if this is a bit off topic, but
don't know if it's a general c++ question or a djgpp - c++ question
either)
Look at:
#include <string.h>
template <class T> class test
{
int a;
char r[34];
public:
test(int integ, char* string);
};
template <class T> test<T>::test(int integ, char* string)
{
a=integ;
strcpy(string,r);
}
int main()
{
test<int> Ttest(1,"S");
}
this works fine, but when changing to the following, the linker says
undefined reference to
the constructor of class <T> test. (look at the position of test<int>
Ttest(1,"S") )
#include <string.h>
template <class T> class test
{
int a;
char r[34];
public:
test(int integ, char* string);
};
template <class T> test<T>::test(int integ, char* string)
{
a=integ;
strcpy(string,r);
}
test<int> Ttest(1,"S");
int main()
{
}
if I change it to the next all works fine. Any idea why. Is this
normal or djgpp - c++ spezific?
Thanks
Michi
#include <string.h>
template <class T> class test
{
int a;
char r[34];
public:
test(int integ, char* string){
a=integ;
strcpy(string,r);
}
};
test<int> Ttest(1,"S");
int main()
{
}
- Raw text -