首页 > 编程语言 > 详细

c++11 继承构造

时间:2017-11-05 15:01:13      阅读:307      评论:0      收藏:0      [点我收藏+]

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;
}

 

c++11 继承构造

原文:http://www.cnblogs.com/lsgxeva/p/7787390.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!