2

When running a c++ class member function from python, i get this error: No Python class registered for C++ class std::string The member function is:

class holiday_calendar {
public:
  const std::string& get_name() const;
  void set_name(const std::string&);
};

I have used this exposing code

class_<holiday_calendar>("holiday_calendar")
.def("getname", &holiday_calendar::get_name, return_internal_reference<>())
.def("setname", &holiday_calendar::set_name);

I can instantiate the object holiday_calendar, I can call setname('SOMENAME') on it but calling getname() fails with the above error

1 Answer 1

7

Your method get_name returns a const std::string&, try this:

class_<holiday_calendar>("holiday_calendar")
.def("getname", &holiday_calendar::get_name, return_value_policy<copy_const_reference>())
.def("setname", &holiday_calendar::set_name);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.