相关疑难解决方法(0)

如何委托基类的不同构造函数并调用派生类构造函数?

我有这个示例代码:

#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';
    }
    A(double i)
    {
        std::cout << "Inside the constructor of A with one double argument" << '\n';
    }
};

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

int main()
{
    B b(12);

    std::cout << …
Run Code Online (Sandbox Code Playgroud)

c++ constructor

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

标签 统计

c++ ×1

constructor ×1