相关疑难解决方法(0)

C++ 中的构造函数继承。派生类的默认构造函数未被调用

我有这个示例代码:

#include <iostream>

class A
{
public:
    A()
    {
        std::cout << "Default constructor of A" << '\n';
    }
    A(int i)
    {
        std::cout << "Inside the constructor of A with one int argument" << '\n';
    }
};

class B : A
{
    using A::A;
public:
    B()
    {
        std::cout << "Default constructor of B" << '\n';
    }
};


int main()
{
    B b(12);

    std::cout << "End of main";
}

Run Code Online (Sandbox Code Playgroud)

哪个输出:

Inside the constructor of A with one int argument
End of main …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance constructor c++17

2
推荐指数
1
解决办法
109
查看次数

标签 统计

c++ ×1

c++17 ×1

constructor ×1

inheritance ×1