Re: name binding from one template to another
Thanks Igor,
1.
Since template symbol is not finalized until it is instantised. But
during the first step of compiler look-up, the compiler only sees the
definition of template, how could it bind (generate binary code to
link to some symbol)
I'm not sure what you are talking about. Name lookup doesn't involve
generating any binary code, let alone linking. It simply establishes
which previously declared entity a name refers to.
When I am talking about bind, I mean refer to some dependent symbol. How
could we refer to a symbol which is not ready (a template without being
instantised) at that time? For example, refer to a (primary) template? I
think we should refer to some concrete type with generated signature/code
other than a template, since template is not the final symbol in the binary
file.
2.
Actually, my confusion comes from the sample we discussed before after
re-thinking. In the below sample, you mentioned before v is not a dependent
name since vector is defined in file vector.
So, it means during the 1st phase of name lookup when compiler parsing the
definition of the template function sum, compiler should make v refers to
something?
If we instantise T to int, compiler should bind v to vector<int> type and
when we instantise T to double, compiler should bind v to vector<double> type.
But actually since T is not given at the time during template definition,
vector<T> is not instantised. How could v refers to something in the 1st
phase of compile?
[Code]
#include <vector>
bool tracing;
/ / ...
template <class T> T sum (std :: vector <T>& v)
{
T t = 0 ;
if (tracing) cerr << "s u m (" << &v << ")\ n ";
for (int i = 0 ; i <v .size(); i ++) t = t + v [i ];
return t ;
}
[/Code]
regards,
George