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>::加以限定。

  • 相关阅读:
    软件工程实践个人编程作业
    实验 2:Mininet 实验——拓扑的命令脚本生成
    软工实践个人总结
    第08组 每周小结 (3/3)
    第08组 每周小结 (2/3)
    第08组 每周小结 (1/3)
    第08组 Beta冲刺 总结
    第08组 Beta冲刺 (5/5)
    第08组 Beta冲刺 (4/5)
    第08组 Beta冲刺 (3/5)
  • 原文地址:https://www.cnblogs.com/5iedu/p/12731331.html
Copyright © 2011-2022 走看看