forked from TNG/boost-python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual.cpp
More file actions
40 lines (34 loc) · 750 Bytes
/
virtual.cpp
File metadata and controls
40 lines (34 loc) · 750 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
#include <iostream>
#include <string>
class Base
{
public:
virtual std::string name() const { return "Base"; }
virtual ~Base() {}
};
void identify(Base *b)
{
std::cout << b->name() << " called." << std::endl;
}
#include <boost/python.hpp>
using namespace boost::python;
struct BaseWrap : Base, wrapper<Base>
{
virtual std::string name() const
{
if (override n = this->get_override("name"))
return n();
return Base::name();
}
std::string default_name() const
{
return this->Base::name();
}
};
BOOST_PYTHON_MODULE(virtual)
{
class_<BaseWrap, boost::noncopyable>("Base")
.def("name", &Base::name, &BaseWrap::default_name)
;
def("identify", identify);
}