Mail Archives: djgpp/1997/04/03/12:52:09
I've been trying to compile some classes that use templates with
DJGPP and I've had no luck. Each time I get unresolved reference errors
when the linked tries to create the executable.
I've read GNU's explanation about template instantiation (sp?), but
it says that one of my options with creating templates is to just pretend
that the compiler works with them properly (at the expense of
unnecessarily duplicated code, however).
I haven't tried the #interface/#implementation method mentioned in
the info file, but I want the code to be fairly portable, so it's not
really an option. The code is similar to the following, which compiles
with the same errors:
-- external.h --:
#ifndef EXT
#define EXT
template<class T>
class Test {
public:
Test(T Value);
void Print(void);
T Storage;
};
// Is this next line needed? (ie: so it's not
// typedef class Test<int> TestInt;
#endif
-- external.cc --:
#include "external.h"
#include <iostream.h>
template<class T>
Test<T>::Test(T Value)
{
Storage = Value;
}
template<class T>
void Test<T>::Print(void)
{
cout << Storage;
}
-- main.cc --:
#include "external.h"
int main(void)
{
// Or TestInt, if line in external.h is uncommented
Test<int> a(24);
a.Print();
return 0;
}
I can't see any real errors in this code, and I think it would
compile correctly under Visual C++. I'm looking for a solution that
uses the compiler flags rather than one that uses other methods. Thanks
in advance,
/\/\att /\/\astracci mmastrac AT acs DOT ucalgary DOT ca
GCS/GE d- s+:+ a--- C++++ UA P+ L E-- W+ N++ o K+ w+ O M- V
PS++ PE++ Y+ PGP t+++ 5+++ X++ R++ tv+ b+++ DI++++ I
G++ e h r* z?
- Raw text -