Mail Archives: djgpp/2001/06/11/13:47:19
Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk> wrote:
> "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.
The standard says here: you need to export the template to make the thing
work:
file class1.h:
template<class TYPE>
class class1 {
private:
TYPE T;
public:
void f1();
};
file class1.cpp:
export template <class TYPE> void class1<TYPE>::f1() {}
But the standard does not require support of the 'export template' construct
because it is not very easy to implement without looking at the source (just
using .o files). So the other compiler is buggy (it exports the template
even if the word 'export' is missing), and gcc is right.
--
#!/usr/bin/perl -w -- sequences
$0=++$|;for(;;){print-length$0;$0=~s/(.)\1*/$1.length$&/ge;}print"\n";
- Raw text -