zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Spring JDBC
    获取JNDI数据源
    subset II
    hadoop-0.20.2安装配置
    leetcode5:subsets问题
    leetcode4:Permutation
    leetCode3
    leetcode2:线性表
    leetcode1:线性表
    使用C++11 开发一个半同步半异步线程池
  • 原文地址:https://www.cnblogs.com/lsgxeva/p/7787390.html
Copyright © 2011-2022 走看看