模板中的名称解析和实例化点 [英] Name resolution and Point of instantiation in Templates

查看:190
本文介绍了模板中的名称解析和实例化点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是ISO C ++标准的语句14.6.4.1实例化点

  4.如果虚拟函数被隐式实例化,它的实例化点
立即跟随它的封装
类模板特化的实例化点。

5.显式实例化指令是由显式
实例化指令指定的
特化或特化的实例化点。

6.取决于
模板参数的表达式的实例化上下文是具有外部链接的声明的集合
在模板的实例化点之前声明
专业化在同一个翻译单元。

我无法为整个部分编写程序。我试图从昨天起为这部分写一个程序。



请尝试问一个或多个点。在任何部分。但是这里我不能理解这一节中的一点。



所以,任何一个人都可以给我一个代码,让这个部分理解。

$前两个语句解释了某些模板构造的实例化点在哪里;它不引入新的模板构造。所以你可以重复使用你以前的例子。



第三个语句(14.6.4.1/6)告诉我们实例化的要点是什么:在名称查找的第二阶段期间查找。在实例化点之前声明为的名称是可见的;那些宣布后不是。 (在两阶段名称查找的第一阶段,在模板定义之前的声明集合中查找非依赖名称)。



所以,给定:

  template< typename T& void foo(){
T()+ T(); $(

表达式的实例化上下文 T T()是在 foo< T> 的相应实例化点之前的声明集。在这些上下文中查找运算符+ ,并包括遵循此定义但在实例化点之前的声明。


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 immediately following the point of instantiation of its enclosing
   class template specialization.

 5.An explicit instantiation directive is an instantiation point for the
   specialization or specializations specified by the explicit 
   instantiation directive.

 6.The instantiation context of an expression that depends on the
   template arguments is the set of declarations with external linkage 
   declared prior to the point of instantiation of the template 
   specialization in the same translation unit.

I am unable to write a programs for this whole section. I am trying to write a programs for this section from yesterday.

Please, normally I would try to ask a 1 or more points. In any section. But here I am unable to understand a single point in this section.

So, kindly can any one provide me a code for this sections to understand.

解决方案

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 <typename T> 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<T>. The name operator+ is looked up in those contexts, and includes declarations that follow this definition but precede the instantiation point.

这篇关于模板中的名称解析和实例化点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆