mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
restructured code in issues.cpp
This commit is contained in:
parent
ffd85b46d8
commit
e707497019
@ -10,20 +10,6 @@
|
||||
#include "example.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) {
|
||||
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; });
|
||||
|
||||
// #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");
|
||||
base.alias<Base>()
|
||||
.def(py::init<>())
|
||||
.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")
|
||||
.def(py::init<int>())
|
||||
|
Loading…
Reference in New Issue
Block a user