[C++-sig] Need help on enum--a concrete example

Min Xu minxu at sci.ccny.cuny.edu
Sat Sep 7 13:44:10 CEST 2002


Hi, 

Thanks for the quick reply. I compiled the code with your changes. The 
compilation failed.

#include <boost/python/module_init.hpp>
#include <boost/python/def.hpp>
#include <boost/python/class.hpp>
//#include <boost/python/implicit.hpp>

enum choice {red, blue};

class A
{
public:
	A() : x(0), y(0) {}
	A(double x, choice c) : x(x), y(c) {}
	double get() { return x; }
	double get1(double x) { return x; }
private:
	double x, y;
};

struct A_wrap : A
{
    A_wrap(PyObject*) : A() {}
    A_wrap(PyObject*, double x, int c) : A(x, (choice)c) {}
};


BOOST_PYTHON_MODULE_INIT(AA)
{
 	using namespace boost::python;

	//implicitly_convertible<int, enum choice>();

	class_<A, A_wrap>("A")
	      .def(init<double, int>())
     	      //.def_init(args<double, choice>())
	      .def("get", &A::get)
	      .def("get1", &A::get1);
}

The compiler complains:
g++ ...
/usr/local/include/boost/python/class.hpp:173:   instantiated from here
/usr/local/include/boost/python/object/value_holder.hpp:120: no matching 
function for call to `A_wrap::A_wrap (PyObject *&, double &)'
AA.C:21: candidates are: A_wrap::A_wrap(PyObject *)
AA.C:22:                 A_wrap::A_wrap(PyObject *, double, int)
AA.C:23:                 A_wrap::A_wrap(const A_wrap &)
make: *** [AA.so] Error 1

Min


On Friday 06 September 2002 23:33, David Abrahams wrote:
> I wrote:
> > struct A_wrap : A
> > {
> >    A_wrap() {}
> >    A_wrap(double x, int c) : A(x, (choice)c) {}
>
> Whoops, that should be:
>
>     A_wrap(PyObject*) {}
>     A_wrap(PyObject*, double x, int c) : A(x, (choice)c) {}
>
>
> -----------------------------------------------------------
>            David Abrahams * Boost Consulting
> dave at boost-consulting.com * http://www.boost-consulting.com
>
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig




More information about the Cplusplus-sig mailing list