zoukankan      html  css  js  c++  java
  • 第5章 技巧性基础:5.3 this->的使用

    5.3 Using this->

    5.3 this->的使用

    For class templates with base classes that depend on template parameters, using a name x by itself is not always equivalent to this->x, even though a member x is inherited. For example:

    对于具有基类的类模板(其基类依赖于模板参数),使用名称x本身往往与this->是不等同的。即使成员x是继承的。例如:

    template<typename T>
    class Base {
    public:
        void bar();
    };
    
    template<typename T>
    class Derived : Base<T> {
    public:
        void foo() {
            bar(); // 调用外部的bar()或者出错
        }
    };

    In this example, for resolving the symbol bar inside foo(), bar() defined in Base is never considered. Therefore, either you have an error, or another bar() (such as a global bar()) is called.

    在这个例子中,为了解析foo()中bar符号,从不考虑基类定义的bar()。因此,这里不是出错,就是调用另一个bar()(如全局的bar())。

    We discuss this issue in Section 13.4.2 on page 237 in detail. For the moment, as a rule of thumb, we recommend that you always qualify any symbol that is declared in a base that is somehow dependent on a template parameter with this-> or Base<T>::.

    我们将在第237页的13.4.2中详细讨论这个问题。目前,作为经验法则:对于那些在基类中声明,并且依赖于模板参数的符号,我们始终建议你应该在它们的前面使用this->或base<T>::加以限定。

  • 相关阅读:
    hive同环比实现
    hive中的to_date和to_char
    正则表达式匹配一个独立的字符
    Mysql Explain用法详解
    hadoop安装踩坑
    hadoop ssh localhost无密码登录
    Node.js第十二篇:图片随机验证码
    Node.js第十一篇:Koa框架基础
    Ajax第五篇:JQuery中使用Ajax
    Ajax第四篇:跨域JSONP、CORS
  • 原文地址:https://www.cnblogs.com/5iedu/p/12731331.html
Copyright © 2011-2022 走看看