Skip to content

Instantly share code, notes, and snippets.

@jkp
Forked from ahankinson/gist:1426301
Created April 2, 2012 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkp/2284716 to your computer and use it in GitHub Desktop.
Save jkp/2284716 to your computer and use it in GitHub Desktop.
Boost Python error "No to_python (by-value) converter found..."
I'm posting this here because I had a maddening search for information about why this error occurs when trying to do certain tasks in a Boost Python binding to a C++ object:
TypeError: No to_python (by-value) converter found for C++ type: Element*
This was when trying to iterate over a vector, defined as:
typedef std::vector<Element*> ElementList;
It turns out that in your `class_<>` definitions you have to be pretty specific. I already had:
class_<Element>("Element")
...
but what solved this error was to specify that this class could _also_ have a pointer type:
class_<Element, Element*>("Element")
...
After adding the pointer type to the class definition, the error went away!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment