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 }