Name resolution and Point of instantiation in Templates

前端 未结 2 1409
日久生厌
日久生厌 2021-01-27 06:32

This is the statement from ISO C++ Standard 14.6.4.1 Point of instantiation

 4.If a virtual function is implicitly instantiated, its point of instantiation
   is         


        
2条回答
  •  半阙折子戏
    2021-01-27 07:11

    The first two statements explain where the instantiation point of certain template constructs are; it doesn't introduce new template constructs. So you can reuse your previous examples.

    The third statement (14.6.4.1/6) tells us what the point of instantiation points is: they are the point where names are looked up during the second phase of name lookup. Names that are declared before the instantiation point are visible; those declared afterwards are not. (In the first phase of two-phase name lookup, non-dependent names are looked up in the set of declarations that precede the template definition).

    So, given:

    template  void foo() {
      T() + T();
    }
    

    the instantiation contexts of the expression T()+T() is the set of declarations that precede the respective instantiation points of foo. The name operator+ is looked up in those contexts, and includes declarations that follow this definition but precede the instantiation point.

提交回复
热议问题