<legend id='kDz4W'><style id='kDz4W'><dir id='kDz4W'><q id='kDz4W'></q></dir></style></legend>

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

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

      1. <small id='kDz4W'></small><noframes id='kDz4W'>

      2. <tfoot id='kDz4W'></tfoot>

        C++11 继承构造函数和访问修饰符

        时间:2023-10-06
      3. <tfoot id='PZe9u'></tfoot>
          <tbody id='PZe9u'></tbody>
        <legend id='PZe9u'><style id='PZe9u'><dir id='PZe9u'><q id='PZe9u'></q></dir></style></legend>
          <bdo id='PZe9u'></bdo><ul id='PZe9u'></ul>

            <small id='PZe9u'></small><noframes id='PZe9u'>

                <i id='PZe9u'><tr id='PZe9u'><dt id='PZe9u'><q id='PZe9u'><span id='PZe9u'><b id='PZe9u'><form id='PZe9u'><ins id='PZe9u'></ins><ul id='PZe9u'></ul><sub id='PZe9u'></sub></form><legend id='PZe9u'></legend><bdo id='PZe9u'><pre id='PZe9u'><center id='PZe9u'></center></pre></bdo></b><th id='PZe9u'></th></span></q></dt></tr></i><div id='PZe9u'><tfoot id='PZe9u'></tfoot><dl id='PZe9u'><fieldset id='PZe9u'></fieldset></dl></div>
                  本文介绍了C++11 继承构造函数和访问修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  假设如下布局:

                  class Base
                  {
                  protected:
                      Base(P1 p1, P2 p2, P3 p3);
                  
                  public:
                      virtual void SomeMethod() = 0;
                  }
                  
                  class Derived : public Base
                  {
                  public:
                      using Base::Base;
                  
                  public:
                      virtual void SomeMethod() override;
                  };
                  

                  我可以在这里将 Derived 的构造函数指定为 public 吗?VC++ 给出以下错误:

                  Should I be able to specify Derived's constructor as public here? VC++ gives the following error:

                  无法访问在类派生"中声明的受保护成员
                  编译器在此处生成了Derived::Derived"[指向使用 Base::Base行]
                  见派生"的声明

                  cannot access protected member declared in class 'Derived'
                  compiler has generated 'Derived::Derived' here [points to the using Base::Base line]
                  see declaration of 'Derived'

                  即它忽略了继承构造函数上方的访问修饰符.

                  i.e. it's ignoring the access modifier above the inherited constructor.

                  这是功能的限制吗?Base 类具有公共构造函数没有任何意义,因为它永远无法直接实例化(由于纯虚方法).

                  Is this a limitation of the feature? It doesn't make any sense for the Base class to have a public constructor, as it can never be instantiated directly (due to the pure virtual method).

                  推荐答案

                  根据12.9/4,继承构造函数",当说using X::X时,

                  According to 12.9/4, "Inheriting constructors", when saying using X::X,

                  如此声明的构造函数与 X 中相应的构造函数具有相同的访问权限.

                  A constructor so declared has the same access as the corresponding constructor in X.

                  所以继承的构造函数也是protected.

                  So the inherited constructor is also protected.

                  这篇关于C++11 继承构造函数和访问修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:StdAfx + 头文件 - MFC 应用程序中的包含顺序 下一篇:为什么在 MSVC 中默认情况下将浮点值(例如 3.14)视

                  相关文章

                  最新文章

                  1. <legend id='ynLal'><style id='ynLal'><dir id='ynLal'><q id='ynLal'></q></dir></style></legend>

                      <bdo id='ynLal'></bdo><ul id='ynLal'></ul>
                    <tfoot id='ynLal'></tfoot>

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

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