1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include <cstdint> 17 #include <cstdlib> 18 #include <iostream> 19 #include <memory> 20 21 class Foo { 22 public: 23 uint8_t a = 1; 24 virtual int get() = 0; 25 }; 26 27 class Foo1 : public Foo { 28 uint16_t b = 2; get()29 virtual int get() override { return b; } 30 }; 31 32 class Foo2 : public Foo { 33 public: 34 uint32_t c = 3; 35 uint32_t cc = 4; get()36 virtual int get() override { return c; } 37 }; 38 39 class Foo3 : public Foo1, public Foo2 { 40 uint32_t d = 4; get()41 virtual int get() override { return d; } 42 }; 43 44 class Foo4 : virtual public Foo { 45 uint16_t b = 2; get()46 virtual int get() override { return b; } 47 }; 48 49 class Foo5 : virtual public Foo { 50 public: 51 uint32_t c = 3; 52 uint32_t cc = 4; get()53 virtual int get() override { return c; } 54 }; 55 56 class Foo6 : public Foo4, public Foo5 { 57 uint32_t d = 4; get()58 virtual int get() override { return d; } 59 }; 60 61 class Bar { 62 public: 63 uint8_t e = 5; 64 }; 65 66 class Bar1 : virtual public Bar { 67 public: 68 uint8_t f = 6; 69 }; 70 main()71int main() { 72 { 73 Foo *x = new Foo1(); 74 Foo *y = new Foo2(); 75 Foo1 *z = new Foo3(); 76 Foo *w = z; 77 Bar *a = new Bar1(); 78 Foo2 b; 79 Foo &c = *w; 80 Foo1 d = *z; 81 b.c += 1; 82 Foo *e = new Foo6(); 83 Foo4 *f = dynamic_cast<Foo6 *>(e); 84 85 delete a; 86 delete x; 87 delete y; 88 delete z; 89 } 90 return 0; 91 }