Created
August 8, 2021 07:25
-
-
Save rajkosto/b86ff97855cb50dd40a6b0bff41340f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
struct DummyBase | |
{ | |
DummyBase() : val(5) {} | |
DummyBase(int newVal) : val(newVal) {} | |
void set_val(int newVal) { val = newVal; } | |
int get_val() const { return val; } | |
private: | |
int val; | |
}; | |
struct RealDummy : public DummyBase | |
{ | |
using DummyBase::DummyBase; | |
string to_string() const { return "MAGIC!"; } | |
}; | |
auto bcs = py::class_<DummyBase>(m,"DummyBase") | |
.def(py::init<>()) | |
.def(py::init<int>()) | |
.def("setVal",[](DummyBase* tgt, int newVal) -> DummyBase* { tgt->set_val(newVal); return tgt; },py::return_value_policy::reference) | |
.def("getVal",[](const DummyBase& tgt) -> int { return tgt.get_val(); }); | |
auto dum = py::class_<RealDummy>(m,"RealDummy",bcs) | |
.def(py::init<>()) | |
.def(py::init<int>()) | |
.def("__str__",[](const RealDummy& tgt) { return tgt.to_string(); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment