mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-19 17:32:37 +00:00
restructured code in issues.cpp
This commit is contained in:
parent
ffd85b46d8
commit
e707497019
@ -10,20 +10,6 @@
|
|||||||
#include "example.h"
|
#include "example.h"
|
||||||
#include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
|
|
||||||
struct Base {
|
|
||||||
virtual void dispatch(void) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DispatchIssue : Base {
|
|
||||||
virtual void dispatch(void) const {
|
|
||||||
PYBIND11_OVERLOAD_PURE(void, Base, dispatch, /* no arguments */);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Placeholder { int i; Placeholder(int i) : i(i) { } };
|
|
||||||
|
|
||||||
void dispatch_issue_go(const Base * b) { b->dispatch(); }
|
|
||||||
|
|
||||||
void init_issues(py::module &m) {
|
void init_issues(py::module &m) {
|
||||||
py::module m2 = m.def_submodule("issues");
|
py::module m2 = m.def_submodule("issues");
|
||||||
|
|
||||||
@ -34,12 +20,22 @@ void init_issues(py::module &m) {
|
|||||||
m2.def("print_char", [](char c) { std::cout << c << std::endl; });
|
m2.def("print_char", [](char c) { std::cout << c << std::endl; });
|
||||||
|
|
||||||
// #159: virtual function dispatch has problems with similar-named functions
|
// #159: virtual function dispatch has problems with similar-named functions
|
||||||
|
struct Base { virtual void dispatch(void) const = 0; };
|
||||||
|
|
||||||
|
struct DispatchIssue : Base {
|
||||||
|
virtual void dispatch(void) const {
|
||||||
|
PYBIND11_OVERLOAD_PURE(void, Base, dispatch, /* no arguments */);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
py::class_<DispatchIssue> base(m2, "DispatchIssue");
|
py::class_<DispatchIssue> base(m2, "DispatchIssue");
|
||||||
base.alias<Base>()
|
base.alias<Base>()
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("dispatch", &Base::dispatch);
|
.def("dispatch", &Base::dispatch);
|
||||||
|
|
||||||
m2.def("dispatch_issue_go", &dispatch_issue_go);
|
m2.def("dispatch_issue_go", [](const Base * b) { b->dispatch(); });
|
||||||
|
|
||||||
|
struct Placeholder { int i; Placeholder(int i) : i(i) { } };
|
||||||
|
|
||||||
py::class_<Placeholder>(m2, "Placeholder")
|
py::class_<Placeholder>(m2, "Placeholder")
|
||||||
.def(py::init<int>())
|
.def(py::init<int>())
|
||||||
|
Loading…
Reference in New Issue
Block a user