Template instantiation...

John Clayton john_clayton@pobox.com
Mon Jun 10 14:46:00 GMT 2002


Hi all, I need a little nudge in the right direction:

I wish to declare a template, then declare specialisations for particular types.  I 
think I am doing the right thing, but no symbols appear in my object file - and 
therefore the programs I'm linking complain loudly.

I understand that if all this stuff goes into the headers, then the 'Borland' model 
is in effect (on systems with 2.8 ld / linux / etc).

I've pasted some example code below, it's cut from the Jace project (which I'm 
modifying to work on Linux).  Oh yes... linux, mandrake 8.1, g++-3.0.1 and the 
following compile options:
	-g -O -fpic

the code goes something like this:
	template <class ResultType> class JMethod
	{
		ResultType invoke( JObject& object, const JArguments& arguments )
		{
			// !!! code ommitted for clarity
			return ResultType( result );
		}
	};

then I want to specialise the template code, which I thought was done like this:

	template<> JMethod<JBoolean>::invoke(JObject& object, const JArguments& arguments)
	{
		// my specialised code goes here
		return JMethod<JBoolean>( /* something */ );
	}


And if all that went into a header I should be laughing right?  Um.  Well.  I am not 
laughing - no symbols in my .o ... are you able to help me??

Many thanks!

-- 
John Clayton



More information about the Gcc-help mailing list