Re: name binding from one template to another

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:89AAF8B5-2E13-484A-A1FD-B8730F09860F@xxxxxxxxxxxxx
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?

The compiler can look up primary template itself in the first phase -
basically, just verify that it exists (in fact, a forward declaration is
sufficient). But any members of that template (whether member types,
data members or member functions) are dependent names and are looked up
in second phase.

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.

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?

What do you mean by "bind" here? If you mean "instantiate", then no, the
compiler won't instantiate vector until it has to instantiate func.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: name binding from one template to another
    ... during the first step of compiler look-up, ... When I am talking about bind, I mean refer to some dependent symbol. ... could we refer to a symbol which is not ready (a template without being ...
    (microsoft.public.vc.language)
  • Re: Template Functions
    ... Templates need to be fully visible to the compiler when it generates ... When you don't have an explicit instantiation, ... it is unable to instantiate ... the template, i.e. create the code for that function. ...
    (microsoft.public.vc.language)
  • Re: template compile errors
    ... gcc throws some strange linking errors. ... code for a template doesn't really exist until you instantiate it... ... compiler generates another set of code and data specific to those types. ...
    (comp.lang.cpp)
  • Re: Member function templates in libraries
    ... > libraries. ... the template functions are instantiated in a cpp file ... It's not possible in any compiler that exists today that doesn't implement ... instantiate it at the time of use because I didn't provide the definition. ...
    (comp.lang.cpp)
  • Re: friend of template class
    ... doesn't actually enforce that) declare the template friend function, ... What actually happens here, is that when you instantiate the template class, ... can't give compiler a hint where to look for it's definition for the ...
    (alt.comp.lang.learn.c-cpp)