c++11 继承构造

c++11 继承构造

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <map>

// C++ 11允许派生类继承基类的构造函数(默认构造函数、复制构造函数、移动构造函数除外)。
/*
注意:
继承的构造函数只能初始化基类中的成员变量,不能初始化派生类的成员变量
如果基类的构造函数被声明为私有,或者派生类是从基类中虚继承,那么不能继承构造函数
一旦使用继承构造函数,编译器不会再为派生类生成默认构造函数
*/
class A
{
public:
    A(int i) { std::cout << "i = " << i << std::endl; }
    A(double d, int i) {}
    A(float f, int i, const char* c) {}
    // ...
};

class B : public A
{
public:
    using A::A; // 继承构造函数
    // ...
    virtual void ExtraInterface(){}
};


void mytest()
{

    return;
}


int main()
{
    mytest();

    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/lsgxeva/p/7787390.html