I haven't tried this myself, but I think all you need to do to wrap the member
function is this:
.def("info", (void(A::*)(int))0, A_info_overloads());
Hope this helps,
Bill
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Hans
Roessler
Sent: Thursday, May 21, 2009 8:40 AM
To: [email protected]
Subject: [C++-sig] variable argument number and
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
Hello,
I try to wrap a class with a function info([int arg]) that takes either zero or
one argument (exact colde below). For some reason I can't get
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to work.
The examples at
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading
and
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec
only show the situation where either
- the *member* function has up to three arguments with default values assigned
or
- three *free* functions have one to three arguments.
I don't find an example where a class has several *member* functions with the
same name, that take a variable number of (non-default!) arguments.
My attempt below gives the error
"pytest.cpp:17: error: no matching function for call to
'boost::python::class_<A, boost::python::detail::not_specified,
boost::python::detail::not_specified,
boost::python::detail::not_specified>::def(const char [5], <unresolved
overloaded function type>, A_info_overloads)'"
Do I have to replace the ".def("info",&A::info, ..." with something like
".def("foo", (void(*)(int,int))0, ..." as shown in the Auto-Overloading section
in the tutorial? If yes, how must this function signature look like? It doesn't
work like this.
Hope someone can help
Hans
=== pytest.py ===
#include <boost/python.hpp>
#include <stdio.h>
using namespace boost::python;
class A{
public:
void info() {printf("This is an A\n");}
void info(int arg) {printf("Unnecessary arg.\n");}
};
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(A_info_overloads, info, 0,1)
BOOST_PYTHON_MODULE(test)
{
class_<A>("A")
.def("info",&A::info,A_info_overloads()) //line 17
;
}
_______________________________________________
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
_______________________________________________
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig