1 Star 1 Fork 1

iounce/Python-Cpp-demo

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
python_class.h 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
iounce 提交于 2023-08-05 22:07 +08:00 . add class demo
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "class.h"
namespace py = pybind11;
class PyBase: public Base
{
public:
using Base::Base;
bool valid() override
{
PYBIND11_OVERRIDE_PURE(
bool,
Base,
valid,
);
}
};
class PyPublicBase: public Base
{
public:
using Base::valid;
};
void initClass(py::module &m)
{
py::class_<Base, PyBase>(m, "Base")
.def(py::init<>())
.def_readwrite_static("type", &Base::m_type)
.def("set", py::overload_cast<int>(&Base::set), "set int value")
.def("set", py::overload_cast<const std::string &>(&Base::set), "set string value")
.def("parse", [](Base &self, std::vector<std::string> args)
{
std::vector<char *> ptrargs;
ptrargs.reserve(args.size());
for (auto &s : args)
{
ptrargs.push_back(const_cast<char *>(s.c_str()));
}
return self.parse(ptrargs.size(), ptrargs.data());
})
.def("valid", &PyPublicBase::valid);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/iounce_admin/python-cpp-demo.git
git@gitee.com:iounce_admin/python-cpp-demo.git
iounce_admin
python-cpp-demo
Python-Cpp-demo
master

搜索帮助