• c


     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 2e5+100;
     4 class Base
     5 {
     6 public:
     7     Base();
     8     Base(int a);
     9     Base(const Base& other);
    10     Base& operator = ( const Base &other);
    11     Base(Base &&other);
    12     Base& operator = (Base&& other);
    13     ~Base();
    14 protected:
    15     int getMemberB()
    16     {
    17         return memberB;
    18     }
    19     int deleteC(int a,int b = 100,bool test = true);
    20 private:
    21     int memberA;
    22     int memberB;
    23     static const int size = 512;
    24     int *pMemberC;
    25 };
    26 class VirtualBase
    27 {
    28 public:
    29     VirtualBase() = default;
    30     virtual ~VirtualBase()
    31     {
    32         cout<<"in virtialBase:~VirtualBase"<<endl;
    33     }
    34     virtual void test1(bool test)
    35     {
    36         cout<<"in virtualBase:testBase1"<<endl;
    37     }
    38     virtual void test2(int x,int y)=0;
    39     void test3(){
    40     cout<<"in virtualBase:test3"<<endl;
    41     }
    42     int vbx;
    43     int vby;
    44 };
    45 class Derived : private Base,public VirtualBase
    46 {
    47 public:
    48     Derived(int x,int y):
    49         Base(x),VirtualBase(),mY(y)
    50     {
    51     };
    52     virtual ~Derived()
    53     {
    54         cout<<"in Derived:~Derived"<<endl;
    55     }
    56 public:
    57     void test1(bool test)override
    58     {
    59         cout<<"in Derived::test1"<<endl;
    60     }
    61     void test2(int x,int y) override
    62     {
    63         cout<<"in Derived::test2"<<endl;
    64     }
    65     void test3()
    66     {
    67         cout<<"in Derived::test3"<<endl;
    68     }
    69 private:
    70     int mY;
    71 };
    72 int main()
    73 {
    74     Derived d(1,1);
    75     cout<<"reference test ============"<<endl;
    76     VirtualBase& vb = d;
    77     vb.test1(true);
    78     vb.test2(0,-1);
    79    vb.test3();
    80     d.test3();
    81 //    cout<<"pointer test ============="<<endl;
    82 //    VirtualBase* pvb= new Derived (1,2);
    83 //    pvb->test1(false);
    84 //    pvb->test2(-1,0);
    85 //    pvb->test3();
    86 //    delete pvb;
    87     return 0;
    88 }
  • 相关阅读:
    MySQL -- 表联结
    Unittest方法 -- 项目实现自动发送邮件
    Linux工作中常用命令
    Requests方法 -- Token获取操作
    Requests方法 -- 关联用例执行
    Requests方法 -- Blog流程类进行关联
    Requests方法 -- 参数化
    defer和async的区别
    js函数收藏:获取cookie值
    XSHELL使用技巧总结
  • 原文地址:https://www.cnblogs.com/letlifestop/p/11108043.html
Copyright © 2020-2023  润新知