Mail Archives: djgpp/2001/06/10/21:16:29
"Tomas Nilsson" <tnidt97 AT student DOT vxu DOT se> wrote:
> Hello,
> I have a problem with templates i djgpp 2.03. I have tried the following
> program:
Put the class declaration *and* implementation in the header:
> file class1.h:
> template<class TYPE>
> class class1 {
> private:
> TYPE T;
> public:
> void f1();
> };
> template <class TYPE> void class1<TYPE>::f1() {}
>
> file main.cpp
> #include"class1.h"
> int main() {
> class1<int> c1;
> c1.f1();
> }
>
> The program compiles without errors and warnings, but then something goes
> wrong in the
> linking process. The linker ld in djgpp returns the error message "undefined
> reference to class<int>::f1(void)". This is very strange, because the UNIX
> compiler CC can compile and build this program without any problem, and CC
> one of the best approximation of the C++ standard I know.
> Can anyone see what could be causing this problem
gcc needs to see the class definition at compile time, otherwise
class1<int> does not exist at link time.
> and why it works in CC and not djgpp?
gcc DTRT here, so strictly speaking the other CC is buggy.
- Raw text -