I have some issue with exposing abstract class to python using Boost.Python lib. I am using 1_53_0 boost and Python 33.
There is a similar thread related to this issue. (How can I implement a C++ class in Python, to be called by C++?) I was following eudoxos response where he makes a wrapper around abstract class Base, which has a method returning string type.
I'm doing something similar but I constantly get a compilation error:
- Error 1 error C2668: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string' : ambiguous call to overloaded function d:\temp\example\example.h 20
- 8 IntelliSense: more than one user-defined conversion from "boost::python::detail::method_result" to "std::string" applies: d:\temp\example\example.h 20
The above errors are related to the line:
return this->get_override("getName")();
From my example shown bellow:
#include <string>
#include "boost/python.hpp"
class Person {
public:
virtual std::string getName() { return "Base"; };
virtual void setName(std::string name) {};
};
class PersonWrap : public Person, public boost::python::wrapper<Person>
{
public:
std::string getName()
{
return this->get_override("getName")();
}
void setName(std::string name)
{
this->get_override("setName")();
}
};
class Student : public Person {
public:
std::string getName() { return myName; };
void setName(std::string name) { myName = name; };
std::string myName;
};
BOOST_PYTHON_MODULE(example)
{
boost::python::class_<PersonWrap, boost::noncopyable>("Person")
.def("getName", (&Person::getName))
.def("setName", (&Person::setName))
;
boost::python::class_<Student, boost::python::bases<Person>>("Student")
.def("getName", (&Student::getName))
.def("setName", (&Student::setName))
;
}
Any comments are appreciated, thanks in advance!