Re: template function instantiation
George wrote:
For the following code from Bjarne's book, it is stated that template
parameter T for function g will be instantised as int other than
double. My question is why there are not two instantiations for both
int and double version of template function g?
^^^^^^^^^^^^^^^^^^^
Huh?
Are you sure about this? There seems to be no "template parameter T
for function g" because there is no function template function g.
There is the template function 'f', which has a template argument
(parameter, if you like).
Care to restate your question? Do you mean 'function template f'?
[Code]
// section C.13.8.3 Point of Instantiatant Binding
template <class T> void f (T a) { g(a); }
^^^^^^^^^^^^
void g(int);
void h()
{
extern g (double);
f (2);
}
[/Code]
Here is the related statement from Bjarne,
--------------------
Each use of a template for a given set of template arguments defines
a point of instantiation.
That point is the nearest global or namespace scope enclosing its use,
just before the declaration that contains that use.
--------------------
Does it before g (double) is not global function or namespace scope
enclosing its use?
Sorry, I don't understand the question, perhaps some words are
missing there. "Does it <WHAT?> before"?
If yes, I do not know why g (double) is not a
global function, since it is declared as extern and some other
compile unit should expose it?
Please review and maybe repost.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask