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

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

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

        <tfoot id='FqOrZ'></tfoot>

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

        C++11 inheriting constructors and access modifiers(C++11 继承构造函数和访问修饰符)
        <tfoot id='o31Jy'></tfoot>

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

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

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

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

                    <tbody id='o31Jy'></tbody>
                1. 本文介绍了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 继承构造函数和访问修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                  Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                  What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                  Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                  Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                  What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)

                  <legend id='97eV1'><style id='97eV1'><dir id='97eV1'><q id='97eV1'></q></dir></style></legend>

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

                    <small id='97eV1'></small><noframes id='97eV1'>

                          • <bdo id='97eV1'></bdo><ul id='97eV1'></ul>