On Jun 19, 3:36 pm, Alan <jalantho...@verizon.netwrote:
Does a template class declaration, like
template <class T>
That's not a template class declaration. Strictly speaking,
there is no such thing as a template class declaration. If you
mean a class template declaration, that would be:
template< ... class ClassTemplate ;
have to come immediately prior to the declaration of the function,
e.g.,
T do_something (T something)
{ . . . }
that uses it?
You seem to be confusing something, although I'm not sure what.
There's nothing in the above function which uses any template
declaration whatsoever.
I have not found anywhere where this rule is written down, but
my compiler seems to work that way.
Work what way? You can use a template class declaration
anywhere it is in scope:
template< typename T class X ;
// anything you want here...
X< int >
doSomething( X< int const& arg )
{ ... }
No problem.
What are you actually trying to do? If you want to declare (or
define) a function template, then you have to use the syntax for
a function template:
template< ... function_declaration
If you want to declare (or define) a class template, you use the
syntax for a class template:
template< ... class_declaration
More generally, if you want to declare (or define) a template,
you precede whatever you want to declare (or define) as a
template with the keyword template, followed by its arguments,
and optionally preceded by the keyword export. Do that, and
you're no longer declaring a class or a function or whatever,
you're declaring a template (which is not a class or a function
until it is instantiated).
Every other declaration seems to
be able to be reused later.
Every declaration can be "reused" later. Otherwise, there would
be no point in making it.
If template worked this way, then one
declaration of the template class would suffice for numerous function
declarations.
It does. Obviously: you use std::vector in an number of
functions, although there is only one declaration of it. The
same holds for every template.
--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34