34 : kind(_kind), name(_name)
42 std::string sound =
"WOOF!";
47 Labrador(
const std::string& _name,
int _excitement = 9001)
55 std::string
bark()
const {
return Dog::bark() +
" and runs in circles"; }
61 std::string
purr()
const {
return "mrowr"; }
67 std::string
purr()
const {
return "mrrrRRRRRR"; }
72 std::vector<std::unique_ptr<Animal>>
ret;
73 ret.emplace_back(
new Labrador(
"Fido", 15000));
80 ret.emplace_back(
new Chihuahua(
"Hertzl"));
82 ret.emplace_back(
new Panther(
"Leo"));
114 template <
typename itype>
117 static const void *
get(
const itype *src,
const std::type_info*&
type)
123 py::class_<Animal>(
m,
"Animal")
125 py::class_<Dog, Animal>(
m,
"Dog")
126 .def(py::init<std::string>())
129 py::class_<Labrador, Dog>(
m,
"Labrador")
130 .def(py::init<std::string, int>(),
"name"_a,
"excitement"_a = 9001)
132 py::class_<Chihuahua, Dog>(
m,
"Chihuahua")
133 .def(py::init<std::string>())
135 py::class_<Cat, Animal>(
m,
"Cat")
136 .def(py::init<std::string>())
138 py::class_<Panther, Cat>(
m,
"Panther")
139 .def(py::init<std::string>())
std::vector< std::unique_ptr< Animal > > create_zoo()
Panther(const std::string &_name)
Animal(const std::string &_name, Kind _kind)
TEST_SUBMODULE(tagbased_polymorphic, m)
PYBIND11_NOINLINE void clean_type_id(std::string &name)
static const std::type_info * type_of_kind(Kind kind)
Dog(const std::string &_name, Kind _kind=Kind::Dog)
static std::string name_of_kind(Kind kind)
Chihuahua(const std::string &_name)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Annotation for function names.
virtual ~Animal()=default
Cat(const std::string &_name, Kind _kind=Kind::Cat)
Labrador(const std::string &_name, int _excitement=9001)