-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinherit.cpp
More file actions
60 lines (45 loc) · 822 Bytes
/
inherit.cpp
File metadata and controls
60 lines (45 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <boost/python.hpp>
#include <iostream>
#include <string>
using namespace std;
struct Base {
virtual ~Base() {}
virtual const char* whoami()
{
return "base";
}
};
struct Derived : public Base {
#if 0
virtual const char* whoami()
{
return "derived";
}
#endif
};
void b(Base* o)
{
cout << "b: " << o->whoami() << endl;
}
void d(Derived* o)
{
cout << "d: " << o->whoami() << endl;
}
Base* factory()
{
return new Derived;
}
BOOST_PYTHON_MODULE(inherit)
{
using namespace boost::python;
class_<Base>("Base")
.def("whoami", &Base::whoami)
;
class_<Derived, bases<Base> >("Derived")
/* sth */
;
def("b", b);
def("d", d);
def("factory", factory,
return_value_policy<manage_new_object>());
}