|
Boost Users : |
Subject: Re: [Boost-users] [Boost.Python] Binding overloaded static functions
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2009-10-20 03:46:02
On Mon, Oct 19, 2009 at 3:42 PM, Dan Bailey <drb_at_[hidden]> wrote:
>
> Hi,
>
> I'm sure this is really trivial, but I'm not sure how to handle overloaded static functions with Boost.Python, and I can't figure it out by going through the documentation.
>
> Here's the simple example I'm trying to compile:
>
> #include <boost/python.hpp>
>
> using namespace boost::python;
>
> class Test
> {
> public:
> Test() { }
> ~Test() { }
> static bool func();
> static bool func(int a);
> };
>
> BOOST_PYTHON_MODULE(test)
> {
> bool (Test::*func1)() = &Test::func);
> class_<Test>("Test")
> //.def("func", func1)
> ;
> }
> Error:
>
> src/main.cpp: In function 'void init_module_test()':
> src/main.cpp:18: error: no matches converting function 'func' to type 'bool (class Test::*)()'
> src/main.cpp:12: error: candidates are: static bool Test::func()
> src/main.cpp:13: error: static bool Test::func(int)
>
> How do I do this?
>
> Thanks,
> Dan
Try a static cast to identify the overload you want:
BOOST_PYTHON_MODULE(test)
{
class_<Test>("Test").def("func", static_cast<bool(*)()>(&Test::func));
}
Stuart Dootson
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net