🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Andre Pareis Fri, 16 Oct 1992 16:36
Trouble with templates in GNU C++
#429
Author: Andre Pareis
Date: Fri, 16 Oct 1992 16:36
91 lines
2933 bytes

Hi C++ users,


I have to implement a generic list class within a class library.
Therefore I want to use templates instead of deriving from on
base class. But my gcc (2.2.2 PL3) does not seem to work correct with it.
(Atari-ST version of G++)

I wrote a little test program (template.cc):


// BEGIN //

template<class T> class A
{
private:
	T a;
public:
	A( T aa ): a(aa) {}
	
	T Get( void );
};



int main( void )
{
	A<int>	a1(2):

	return a1.Get();
}


template<class T> T A<T>::Get( void )
{
	return a;
}

// END //


The compiler works fine, but the linker aborts with a message like:

template.o: A<int>::Get  - symbol not found     ( or the like )


But, if I put the definition of Get directly below the class A
declaration, it works. I want to know: Is it a problem of the C++
language or the compiler or the linker (which is PL31)?



It seems to me, it is a bug (or something else) of either the GNU compiler
or the linker. ( An earlier version of G++ (2.1) gave the same results )
I tried these lines on a Sparc with G++ 2.2.2, and got this message:

	ld: Undefined symbol 
	   _Get__t1A1Zi 

After, I made A( T aa ) non-inline, i.e., put it's definition at the end
of the file and got the same messages for A(T).
Then I put both non-inline functions between the class declaration and
main() and (surprisingly) IT WORKED?



Is there somebody in this group who had the same problems with templates
and G++? Or do I have simply to turn on a compiler or linker switch?
Until a resolution is found, I have to write all the list code in one
file List.h, which will be included by other modules, then all works
correct, except that I have to wait a very long time for every compilation.


Another question is:
In the infos about libg++ I found a description of generic list,
stack and queue classes, but my g++ lib doesn't contain such things.
Is it impossible to implement it with G++?



				Thanks in advance

				+-----------------------------------------------+
				| Andr'e Pareis |  Techn. University of Berlin	|
				|-----------------------------------------------|
				| e-mail:    pareis@cs.tu-berlin.de		|
				|	     subiaagb@w350zrz.zrz.tu-berlin.de	|
				| NeXT-mail: subiaagb@w271zrz.zrz.tu-berlin.de  |
				+-----------------------------------------------+
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads