Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost.Python static method overloads

How do I expose the following class using Boost.Python?

class C {
 public:
  static void F(int) {}
  static void F(double) {}
};

I tried something like this:

bp::class_<C>("C")
  .def("F", (void (C::*)(int))&C::F).staticmethod("F")
  .def("F", (void (C::*)(double))&C::F).staticmethod("F")
;

But, it raises an exception in Python (SystemError: initialization of libdistributions raised unreported exception). If I remove one of the overloads from the bp::class_, then everything works fine. I know that Boost.Python can automatically deal with overloaded constructors, so I was wondering if there was something like that for static methods.


Answer

bp::class_<C>("C")
  .def("F", (void (C::*)(int))&C::F)  // Note missing staticmethod call!
  .def("F", (void (C::*)(double))&C::F).staticmethod("F")
;
like image 620
Neil G Avatar asked Jan 03 '12 16:01

Neil G


1 Answers

I think here you can find the solution to your problem:

http://www.boost.org/doc/libs/1_48_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading

like image 169
Andrey Antukh Avatar answered Nov 18 '22 09:11

Andrey Antukh