Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-10-31 09:15:35


----- Original Message -----
From: "Anton Gluck" <gluc_at_[hidden]>

> And now for something completely different:
>
> There is a function AddVar in one of the classes I'm trying to expose to
> Python. AddVar is defined like this in the header file:
>
> void AddVar(double d1 = 0, double d2 = 1.0);
>
> In the source file it is implemented like this:
>
> void MyClass::AddVar(double d1, double d2) {
> // set the variables
> }
>
> So that in the end only AddVar(double, double) is in the source file, with
> an implied no-args overload because of the definition in the header file.
> When I wrap this function in py_cpp with
>
> MyClass_class.def(MyClass::AddVar, "AddVar");
>
> quite understandably only the version of AddVar with the two doubles as
> arguments is exposed. How can I get a no-args version to be exposed also?

Just add an overload:

static void myclass_addvar0(MyClass& x)
{
  x.AddVar();
}
...
MyClass_class.def(myclass_addvar0, "AddVar");

If you care about the 1-argument version, you can do the same with:

static void myclass_addvar1(MyClass& x, double d1)
{
  x.AddVar(d1);
}
...
MyClass_class.def(myclass_addvar1, "AddVar");

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk