forked from pybind/pybind11
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for multiple inheritance
- Loading branch information
1 parent
19d95ef
commit 8158622
Showing
9 changed files
with
174 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ set(PYBIND11_EXAMPLES | |
example15.cpp | ||
example16.cpp | ||
example17.cpp | ||
example18.cpp | ||
issues.cpp | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
example/example18.cpp -- Multiple inheritance support | ||
Copyright (c) 2016 Boris Schäling <boris@highscore.de> | ||
All rights reserved. Use of this source code is governed by a | ||
BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
|
||
#include "example.h" | ||
|
||
struct MIParent1 { | ||
virtual ~MIParent1() = default; | ||
|
||
virtual void virtualParent1() { | ||
std::cout << "virtual parent1\n"; | ||
} | ||
|
||
void nonvirtualParent1() { | ||
std::cout << "nonvirtual parent1\n"; | ||
} | ||
|
||
virtual void virtualOverride() { | ||
} | ||
}; | ||
|
||
struct MIParent2 { | ||
virtual ~MIParent2() = default; | ||
|
||
virtual void virtualParent2() { | ||
std::cout << "virtual parent2\n"; | ||
} | ||
|
||
void nonvirtualParent2() { | ||
std::cout << "nonvirtual parent2\n"; | ||
} | ||
}; | ||
|
||
struct MIChild1 : MIParent1, MIParent2 { | ||
void child1() { | ||
std::cout << "child1\n"; | ||
} | ||
|
||
void virtualOverride() override { | ||
std::cout << "override\n"; | ||
} | ||
}; | ||
|
||
void init_ex18(py::module &m) { | ||
py::class_<MIParent1>(m, "MIParent1") | ||
.def("virtualParent1", &MIParent1::virtualParent1) | ||
.def("nonvirtualParent1", &MIParent1::nonvirtualParent1) | ||
.def("virtualOverride", &MIParent1::virtualOverride); | ||
|
||
py::class_<MIParent2>(m, "MIParent2") | ||
.def("virtualParent2", &MIParent2::virtualParent2) | ||
.def("nonvirtualParent2", &MIParent2::nonvirtualParent2); | ||
|
||
py::class_<MIChild1>(m, "MIChild1", py::bases<MIParent1, MIParent2>()) | ||
.def(py::init<>()) | ||
.def("child1", &MIChild1::child1) | ||
.def("virtualOverride", &MIChild1::virtualOverride); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
from example import MIChild1 | ||
|
||
c = MIChild1() | ||
c.virtualParent1() | ||
c.nonvirtualParent1() | ||
c.virtualParent2() | ||
c.nonvirtualParent2() | ||
c.child1() | ||
c.virtualOverride() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
virtual parent1 | ||
nonvirtual parent1 | ||
virtual parent2 | ||
nonvirtual parent2 | ||
child1 | ||
override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters