[C++-sig] TypeError: bad argument type for built-in operation

Min Xu minxu at sci.ccny.cuny.edu
Thu Jun 6 17:53:48 CEST 2002


I am troubled by this error for a long time even for a simple code. Can
anyone give me hints what is wrong here? Thanks. 

Output:

% compiles OK.
% python2.2 -c "import AA; print AA.AA().get1()"
Traceback (most recent call last):
  File "<string>", line 1, in ?
TypeError: bad argument type for built-in operation


The simple code list:

#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/ref.hpp>
#include <boost/utility.hpp>
using namespace boost::python;

class A
{
public:
	A() : x(0) {}
	virtual double get() = 0;
	virtual double get1(double x) = 0;
private:
	double x;
};


class AA : public A
{
public:
	AA() : A() {}
	double get() { return 0; }
	double get1(double x) { return x; }
	double get2(double x, double y) { return y+x; }
};


BOOST_PYTHON_MODULE_INIT(AA)
{
      module m("AA");
	  m.add(
	      class_<A, boost::noncopyable>("A")
	      .def("get", &A::get)
	      .def("get1", &A::get1)
	      );
	  m.add(
	      class_<AA, bases<A> >("AA")
	      .def_init(args<>())
	      .def("get2", &AA::get2)
	      );
}




Min Xu







More information about the Cplusplus-sig mailing list