Skip to content

To customize or not smart pointers? #5140

Closed Answered by andre-caldas
andre-caldas asked this question in Q&A
Discussion options

You must be logged in to vote

I found out that probably the simplest solution is to:

  1. Implement a private constructor that takes a pointer.
  2. Make template<...> class pybind11::class_ a friend class.
private:
  SharedPtr(T* ptr) : std::shared_ptr<T>(ptr) {}
  template <typename type_, typename... options>
  friend class pybind11::class_;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andre-caldas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant