🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1458

gcc 2.3.1 bug with templates in c++

#1458
From: Seth C. Goldstein
Date: Sat, 21 Nov 1992 05:49
51 lines
1473 bytes
Machine:	sparc
Version:	gcc version 2.3.1
OS:		SunOS Release 4.1.2
problem:	
1 - The methods in a parameterized class are not implemented by the compiler
    if the definitions are not included in the class definition.  For
    example:

	//////////////////////////////// bar.h
	template<class T>
	class Bar
	{
		T data;
	public:
		inline Bar(T i);
		T get(void);
	};
	
	
	template<class T> inline 
	Bar<T>::Bar(T i)
	{
		data = i;
	}
	//////////////////////////////// EOF
	//////////////////////////////// bar.C
	#include "bar.h"
	
	template<class T> T
	Bar<T>::get(void)
	{
		return data;
	}
	//////////////////////////////// EOF
	//////////////////////////////// user.C
	#include <stdio.h>
	#include "bar.h"
	
	main()
	{
		Bar<int> bi(2);
	
		printf("%d\n", bi.get());
	}
	//////////////////////////////// EOF

    when compiled with: gcc-2.3.1 -o test bar.C user.C generates the
    following linktime error:

	ld: Undefined symbol 
	   _get__t3Bar1Zi 
Technical Details
Message-ID: <9211212149.AA20903@boing.CS.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.berkeley.edu!sethg

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.berkeley.edu!sethg
From: sethg@cs.berkeley.edu (Seth C. Goldstein)
Subject: gcc 2.3.1 bug with templates in c++
Message-ID: <9211212149.AA20903@boing.CS.Berkeley.EDU>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sat, 21 Nov 1992 05:49:54 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 53