🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #429

Trouble with templates in GNU C++

#429
From: 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  |
				+-----------------------------------------------+
Technical Details
Message-ID: <P1Z7T4W@mailgzrz.tu-berlin.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!dct.zrz.tu-berlin.de!zrz.tu-berlin.de!w350zrz!subiaagb

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!dct.zrz.tu-berlin.de!zrz.tu-berlin.de!w350zrz!subiaagb
From: subiaagb@w350zrz.zrz.tu-berlin.de (Andre Pareis)
Subject: Trouble with templates in GNU C++
Message-ID: <P1Z7T4W@mailgzrz.tu-berlin.de>
Sender: subiaagb@w350zrz (Andre Pareis)
Nntp-Posting-Host: w350zrz.zrz.tu-berlin.de
Reply-To: pareis@cs.tu-berlin.de
Organization: Dept. of CS, Techn. University Berlin
Date: Fri, 16 Oct 1992 16:36:16 GMT
Lines: 91