template question.

Satish satish@dakotacom.net
Wed Oct 14 21:17:00 GMT 1998


Hi,

I have just started using the egcs-1.0.3 compiler.
I ran into a problem which works fine with SGI CC
compiler. Can you please point out how to make it
work.

Here is a sample that shows the problem..

I get these errors trying to compile the basic skeleton programs
shown below:
Undefined                       first referenced
 symbol                             in file
Foo<Bar *>::Foo(void)               /var/tmp/cc0wXca01.o
ld: fatal: Symbol referencing errors. No output written to tmp
collect2: ld returned 1 exit status

Also, the presence of def. for operator<< (comments removed)
causes the following error, where I expected it to work just fine..
Do I need to use -fguiding-decls?

In file included from main.C:2:
templ.h:12: warning: friend declaration `class ostream & operator
<<(class ostream &, const class Foo<T> &)'
templ.h:12: warning:   will not be treated as a template instantiation
templ.h:12: warning:   unless you compile with -fguiding-decls
templ.h:12: warning:   or add <> after the function name


The file listings are as follows:
main.C
-------
#include "templ.h"
#include "bar.h"

void main( void ){
  Foo<Bar*>* foo = new Foo<Bar*>();
}

templ.C
-------
#include "templ.h"

template <class T>
Foo<T>::Foo( void ) {
}

template <class T>
void Foo<T>::bar( T& t ) const {
}

/*
template <class T>
ostream& operator<<( ostream& os, const Foo<T>& t ) {
  return os;
}
*/

templ.h
-------
#ifndef TEMPL_H_
#define TEMPL_H_

#include <iostream.h>

template <class T>
class Foo {
public:
  Foo( void );
  void bar( T& t ) const;
  //friend ostream& operator<<( ostream&, const Foo<T>& );
};

#endif

Thanks,
Satish.





More information about the Gcc mailing list