This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Template instantiation...
- From: John Clayton <john_clayton at pobox dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 10 Jun 2002 22:53:15 +0100
- Subject: Template instantiation...
- Reply-to: john_clayton at pobox dot com
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