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.
Do I correctly describe both mine and yours ideas?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; }
If yes, please read the words from Bjarne, section C.13.8.3 Point of Instantiation Binding
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).Code:template class <T> void f (T a) { g(a); } void g (int); void h() { extern g (double); f (2); }
Seems your points conflict with Bjarne's? :-)
Any comments?
regards,
George



LinkBack URL
About LinkBacks




CornedBee