Skip to content

Commit 698fa59

Browse files
committed
pybind.cpp
1 parent 0a38f4a commit 698fa59

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

section4/pybind.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@
1616

1717
using namespace std;
1818

19+
class Point final
20+
{
21+
private:
22+
int x = 0;
23+
public:
24+
Point() = default;
25+
~Point() = default;
26+
27+
Point(int a) : x(a) {}
28+
public:
29+
int get() const
30+
{
31+
return x;
32+
}
33+
34+
void set(int a)
35+
{
36+
x = a;
37+
}
38+
};
39+
1940
PYBIND11_MODULE(pydemo, m)
2041
{
2142
m.doc() = "pybind11 demo doc";
@@ -35,6 +56,13 @@ PYBIND11_MODULE(pydemo, m)
3556
return a + b;
3657
}
3758
);
59+
60+
pybind11::class_<Point>(m, "Point")
61+
.def(pybind11::init())
62+
.def(pybind11::init<int>())
63+
.def("get", &Point::get)
64+
.def("set", &Point::set)
65+
;
3866
}
3967

4068
#if 0

0 commit comments

Comments
 (0)