brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 4d29af1 Raw
88 lines · cpp
1int main(int argc, char** argv)2{3  struct A {4    int a_;5  } a{1};6 7  struct B {8    int b_;9  } b{2};10 11  struct C : A, B {12    int c_;13  } c;14  //  } c{{1}, {2}, 3};15  c.a_ = 1;16  c.b_ = 2;17  c.c_ = 3;18 19  struct D : C {20    int d_;21    A fa_;22  } d;23  //  } d{{{1}, {2}, 3}, 4, {5}};24  d.a_ = 1;25  d.b_ = 2;26  d.c_ = 3;27  d.d_ = 4;28  d.fa_.a_ = 5;29 30  // Virtual inheritance example.31  struct Animal {32    virtual ~Animal() = default;33    int weight_;34  };35  struct Mammal : virtual Animal {};36  struct WingedAnimal : virtual Animal {};37  struct Bat : Mammal, WingedAnimal {38  } bat;39  bat.weight_ = 10;40 41 // Empty bases example.42  struct IPlugin {43    virtual ~IPlugin() {}44  };45  struct Plugin : public IPlugin {46    int x;47    int y;48  };49  Plugin plugin;50  plugin.x = 1;51  plugin.y = 2;52 53  struct ObjectBase {54    int x;55  };56  struct Object : ObjectBase {};57  struct Engine : Object {58    int y;59    int z;60  };61 62  Engine engine;63  engine.x = 1;64  engine.y = 2;65  engine.z = 3;66 67  // Empty multiple inheritance with empty base.68  struct Base {69    int x;70    int y;71    virtual void Do() = 0;72    virtual ~Base() {}73  };74  struct Mixin {};75  struct Parent : private Mixin, public Base {76    int z;77    virtual void Do(){};78  };79  Parent obj;80  obj.x = 1;81  obj.y = 2;82  obj.z = 3;83  Base* parent_base = &obj;84  Parent* parent = &obj;85 86  return 0; // Set a breakpoint here87}88