Thanks CornedBee,
Actually, my confusion comes from the sample we discussed before after re-thinking. In the below sample, Bjarne 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 ;
}
Originally Posted by
CornedBee
It can bind vector<T> to the std::vector template easily. That doesn't mean it generates code for it yet.
regards,
George