Skip to content

Instantly share code, notes, and snippets.

@ahankinson
Created December 3, 2011 06:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahankinson/1426301 to your computer and use it in GitHub Desktop.
Save ahankinson/1426301 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!
@jkp
Copy link

jkp commented Apr 2, 2012

Brilliant...I was on the same maddening hunt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment