• <i id='V83SL'><tr id='V83SL'><dt id='V83SL'><q id='V83SL'><span id='V83SL'><b id='V83SL'><form id='V83SL'><ins id='V83SL'></ins><ul id='V83SL'></ul><sub id='V83SL'></sub></form><legend id='V83SL'></legend><bdo id='V83SL'><pre id='V83SL'><center id='V83SL'></center></pre></bdo></b><th id='V83SL'></th></span></q></dt></tr></i><div id='V83SL'><tfoot id='V83SL'></tfoot><dl id='V83SL'><fieldset id='V83SL'></fieldset></dl></div>

      <bdo id='V83SL'></bdo><ul id='V83SL'></ul>

      <legend id='V83SL'><style id='V83SL'><dir id='V83SL'><q id='V83SL'></q></dir></style></legend>
    1. <small id='V83SL'></small><noframes id='V83SL'>

      <tfoot id='V83SL'></tfoot>

      1. 复制构造函数不被继承

        时间:2023-08-02
          <i id='3CZmQ'><tr id='3CZmQ'><dt id='3CZmQ'><q id='3CZmQ'><span id='3CZmQ'><b id='3CZmQ'><form id='3CZmQ'><ins id='3CZmQ'></ins><ul id='3CZmQ'></ul><sub id='3CZmQ'></sub></form><legend id='3CZmQ'></legend><bdo id='3CZmQ'><pre id='3CZmQ'><center id='3CZmQ'></center></pre></bdo></b><th id='3CZmQ'></th></span></q></dt></tr></i><div id='3CZmQ'><tfoot id='3CZmQ'></tfoot><dl id='3CZmQ'><fieldset id='3CZmQ'></fieldset></dl></div>

              <bdo id='3CZmQ'></bdo><ul id='3CZmQ'></ul>

                <legend id='3CZmQ'><style id='3CZmQ'><dir id='3CZmQ'><q id='3CZmQ'></q></dir></style></legend>
                  <tbody id='3CZmQ'></tbody>

                <small id='3CZmQ'></small><noframes id='3CZmQ'>

                1. <tfoot id='3CZmQ'></tfoot>

                  本文介绍了复制构造函数不被继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有以下代码:

                  class C {
                  public:
                      C(int) {}
                      C(const C&) {}
                      C() {}
                  };  
                  
                  class D : public C { 
                  public:
                      using C::C;
                  };  
                  
                  int main() {
                      C c;
                      D d_from_c(c); // does not compile, copy ctor is not inherited
                      D d_from_int(1); // compiles, C(int) is inherited
                  }   
                  

                  派生类应该继承除默认构造函数之外的所有基构造函数(解释为 here).但是为什么 copy ctor 也没有被继承呢?此处不接受来自相关问题的论点.

                  Derived class should inherit all ctors of base except the default ctor (it is explained here). But why copy ctor is not inherited as well? Arguments from the related question are not acceptable here.

                  代码是用g++ 4.8.1编译的.

                  The code is compiled with g++ 4.8.1.

                  推荐答案

                  因为标准是这么说的.[class.inhctor]/p3,强调我的:

                  Because the standard says so. [class.inhctor]/p3, emphasis mine:

                  对于候选集合中的每个非模板构造函数构造函数除了没有参数的构造函数或具有单个参数的复制/移动构造函数,构造函数是使用相同的构造函数特性隐式声明,除非有一个用户声明的构造函数具有相同的签名出现 using 声明或构造函数的完整类将是该类的默认构造函数、复制构造函数或移动构造函数.

                  For each non-template constructor in the candidate set of inherited constructors other than a constructor having no parameters or a copy/move constructor having a single parameter, a constructor is implicitly declared with the same constructor characteristics unless there is a user-declared constructor with the same signature in the complete class where the using-declaration appears or the constructor would be a default, copy, or move constructor for that class.

                  这篇关于复制构造函数不被继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:继承:“A"是“B"的不可访问的基础 下一篇:基类中的静态变量是否由所有派生类共享?

                  相关文章

                  最新文章

                2. <small id='kKOe6'></small><noframes id='kKOe6'>

                    <bdo id='kKOe6'></bdo><ul id='kKOe6'></ul>

                  1. <i id='kKOe6'><tr id='kKOe6'><dt id='kKOe6'><q id='kKOe6'><span id='kKOe6'><b id='kKOe6'><form id='kKOe6'><ins id='kKOe6'></ins><ul id='kKOe6'></ul><sub id='kKOe6'></sub></form><legend id='kKOe6'></legend><bdo id='kKOe6'><pre id='kKOe6'><center id='kKOe6'></center></pre></bdo></b><th id='kKOe6'></th></span></q></dt></tr></i><div id='kKOe6'><tfoot id='kKOe6'></tfoot><dl id='kKOe6'><fieldset id='kKOe6'></fieldset></dl></div>
                    <tfoot id='kKOe6'></tfoot>

                  2. <legend id='kKOe6'><style id='kKOe6'><dir id='kKOe6'><q id='kKOe6'></q></dir></style></legend>