fail to export class inheriting from std::enable_shared_from_this
Open
Nobody has claimed this yet.
casters
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Hello
I got an error when exposing a class inheriting from std::enable_shared_from_this. The code is below
struct Dog : public std::enable_shared_from_this<Dog> {
Dog(const std::string &name) : name(name) { }
void setName(const std::string &name_) { name = name_; }
const std::string &getName() const { return name; }
std::string name;
};
PYBIND11_MODULE(example, m) {
pybind11::class_<Dog>(m, "Dog")
.def(pybind11::init<const std::string &>())
.def("setName", &Pet::setName)
.def("getName", &Pet::getName);
}
The error I have is:
/home/hbui/sw/pybind11/include/pybind11/pybind11.h:1279:17: error: no matching function for call to ‘std::unique_ptr<Dog, std::default_delete<Dog> >::unique_ptr(std::remove_reference<std::shared_ptr<Dog>&>::type)’
new (std::addressof(v_h.holder<holder_type>())) holder_type(std::move(sh));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can anyone suggest a solution for it? Thanks in advance.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Dog example and the reported construction failure at pybind11/pybind11.h:1279. Trace the holder type selected by the class_ declaration and reproduce the error before checking related binding tests; done means the example exports a class inheriting from std::enable_shared_from_this without the reported compilation failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100