[C++-sig] Providing a default value for a pointer argument
Matthias Baas
baas at ira.uka.de
Wed Mar 22 14:29:45 CET 2006
Hi,
I have a question about the "arg" class which can be used to provide
names for keyword arguments and their default values. Should this
default value also be taken into account for arguments that are actually
pointers?
I have a function that takes a pointer as input whose default value in C
is 0. When I wrap that function I provide the default value as
arg("...")=0. I get no error when compiling such a module but the
default value seems to be ignored and I must specify an argument
explicitly (whereas I would have expected the default value to be None).
So is this a bug or just normal behavior? Below is a sample module that
shows the problem. In this example it should be possible to call
ptrarg() without any arguments, but when I do this I get the following
error:
Boost.Python.ArgumentError: Python argument types in
mod.ptrarg()
did not match C++ signature:
ptrarg(class Spam * s=0)
Well, I do know how I can rewrite the module so that it does what I want
(using thin wrappers, BOOST_PYTHON_FUNCTION_OVERLOADS, etc), I just
thought I ask anyway because using "arg" would be rather convenient and
maybe this is a bug in Boost.Python (as it also doesn't generate an
error)...
- Matthias -
// Sample program:
#include <boost/python.hpp>
using namespace boost::python;
class Spam
{
};
int ptrarg(Spam* s=0)
{
if (s==0)
return 0;
else
return 1;
}
BOOST_PYTHON_MODULE(mod)
{
class_<Spam>("Spam", init<>());
def("ptrarg", ptrarg, (arg("s")=0));
}
More information about the Cplusplus-sig
mailing list