-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return best representation of polymorphic types (fixes #105)
- Loading branch information
Showing
6 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
example/example16.cpp -- automatic upcasting for polymorphic types | ||
Copyright (c) 2015 Wenzel Jakob <[email protected]> | ||
All rights reserved. Use of this source code is governed by a | ||
BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
|
||
#include "example.h" | ||
|
||
struct BaseClass { virtual ~BaseClass() {} }; | ||
struct DerivedClass1 : BaseClass { }; | ||
struct DerivedClass2 : BaseClass { }; | ||
|
||
void init_ex16(py::module &m) { | ||
py::class_<BaseClass>(m, "BaseClass").def(py::init<>()); | ||
py::class_<DerivedClass1>(m, "DerivedClass1").def(py::init<>()); | ||
py::class_<DerivedClass2>(m, "DerivedClass2").def(py::init<>()); | ||
|
||
m.def("return_class_1", []() -> BaseClass* { return new DerivedClass1(); }); | ||
m.def("return_class_2", []() -> BaseClass* { return new DerivedClass2(); }); | ||
m.def("return_none", []() -> BaseClass* { return nullptr; }); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<class 'example.DerivedClass1'> | ||
<class 'example.DerivedClass2'> | ||
<type 'NoneType'> |
This file contains 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