Thanks Elysia,
Sorry I do not agree your below quoted text. I have made a program to make the discussion clear. For example, in the following code,
1. I think f is instantised when we define function g, and T is int, deduced by the definition of g;
2. You think it is f (100) inside main which instantise function f with parameter type t to int.
Code:
#include <iostream>
using namespace std;
template <class T> void f(T a) {g (a);}
void g (int a)
{
cout << a << endl;
}
int main()
{
f (100);
return 0;
}
Do I correctly describe both mine and yours ideas?
If yes, please read the words from Bjarne, section C.13.8.3 Point of Instantiation Binding
Code:
template class <T> void f (T a) { g(a); }
void g (int);
void h()
{
extern g (double);
f (2);
}
Bjarne said, the point of instantiation for f<int> is just before h(), so the g() called in f() is the global g(int) rather than the local g (double).
Seems your points conflict with Bjarne's? :-)
Any comments?
Originally Posted by
Elysia
If you listen, you'll know that the compiler will not deduce a template type depending on the contents of the function itself.
regards,
George