| 81 | } // namespace |
| 82 | |
| 83 | TEST_SUBMODULE(multiple_inheritance, m) { |
| 84 | // Please do not interleave `struct` and `class` definitions with bindings code, |
| 85 | // but implement `struct`s and `class`es in the anonymous namespace above. |
| 86 | // This helps keeping the smart_holder branch in sync with master. |
| 87 | |
| 88 | // test_multiple_inheritance_mix1 |
| 89 | // test_multiple_inheritance_mix2 |
| 90 | struct Base1 { |
| 91 | explicit Base1(int i) : i(i) {} |
| 92 | int foo() const { return i; } |
| 93 | int i; |
| 94 | }; |
| 95 | py::class_<Base1> b1(m, "Base1"); |
| 96 | b1.def(py::init<int>()).def("foo", &Base1::foo); |
| 97 | |
| 98 | struct Base2 { |
| 99 | explicit Base2(int i) : i(i) {} |
| 100 | int bar() const { return i; } |
| 101 | int i; |
| 102 | }; |
| 103 | py::class_<Base2> b2(m, "Base2"); |
| 104 | b2.def(py::init<int>()).def("bar", &Base2::bar); |
| 105 | |
| 106 | // test_multiple_inheritance_cpp |
| 107 | struct Base12 : Base1, Base2 { |
| 108 | Base12(int i, int j) : Base1(i), Base2(j) {} |
| 109 | }; |
| 110 | struct MIType : Base12 { |
| 111 | MIType(int i, int j) : Base12(i, j) {} |
| 112 | }; |
| 113 | py::class_<Base12, Base1, Base2>(m, "Base12"); |
| 114 | py::class_<MIType, Base12>(m, "MIType").def(py::init<int, int>()); |
| 115 | |
| 116 | // test_multiple_inheritance_python_many_bases |
| 117 | #define PYBIND11_BASEN(N) \ |
| 118 | py::class_<BaseN<(N)>>(m, "BaseN" #N).def(py::init<int>()).def("f" #N, [](BaseN<N> &b) { \ |
| 119 | return b.i + (N); \ |
| 120 | }) |
| 121 | PYBIND11_BASEN(1); |
| 122 | PYBIND11_BASEN(2); |
| 123 | PYBIND11_BASEN(3); |
| 124 | PYBIND11_BASEN(4); |
| 125 | PYBIND11_BASEN(5); |
| 126 | PYBIND11_BASEN(6); |
| 127 | PYBIND11_BASEN(7); |
| 128 | PYBIND11_BASEN(8); |
| 129 | PYBIND11_BASEN(9); |
| 130 | PYBIND11_BASEN(10); |
| 131 | PYBIND11_BASEN(11); |
| 132 | PYBIND11_BASEN(12); |
| 133 | PYBIND11_BASEN(13); |
| 134 | PYBIND11_BASEN(14); |
| 135 | PYBIND11_BASEN(15); |
| 136 | PYBIND11_BASEN(16); |
| 137 | PYBIND11_BASEN(17); |
| 138 | |
| 139 | // Uncommenting this should result in a compile time failure (MI can only be specified via |
| 140 | // template parameters because pybind has to know the types involved; see discussion in #742 |
nothing calls this directly
no test coverage detected