Hello everyone,
For non-template function/class, compiler knows the symbol is there and bind to a definite symbol. It is straight forward to understand.
But for a two-step name-lookup compiler, I am curious, how did compiler binds another referred template from one template in the first name lookup step, before instantiation?
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) (before a referred template is instantised, the real code is not generated)?
For example, in the following code, during the 1st step of name-lookup before function func is instantised, how did compiler work internally to bind to vector<T> (T is not ready at this time, so vector<T> is not instantised)?
Or, I am wrong that compiler will do nothing to bind the referred template, like vector<T> in the sample?
thanks in advance,
George
For non-template function/class, compiler knows the symbol is there and bind to a definite symbol. It is straight forward to understand.
But for a two-step name-lookup compiler, I am curious, how did compiler binds another referred template from one template in the first name lookup step, before instantiation?
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) (before a referred template is instantised, the real code is not generated)?
For example, in the following code, during the 1st step of name-lookup before function func is instantised, how did compiler work internally to bind to vector<T> (T is not ready at this time, so vector<T> is not instantised)?
Or, I am wrong that compiler will do nothing to bind the referred template, like vector<T> in the sample?
Code:
template <class T> void func (T a)
{
vector<T> vc;
vc.push_back (a);
// ...
}
thanks in advance,
George