Boost logo

Boost :

From: John Hunter (jdhunter_at_[hidden])
Date: 2001-08-16 17:26:10


>>>>> "Ralf" == Ralf W Grosse-Kunstleve <rwgk_at_[hidden]> writes:

    Ralf> with optional arguments. However, the default arguments are
    Ralf> lost at the Python level. Therefore I usually define *free*
    Ralf> C++ functions, e.g.:

That works perfectly for me. Do you have a similarly clever trick for
classes with several constructors, each of which takes (the same)
optional argument as the last arg?

class SomeClass {
public:
  SomeClass( int i = 5) { ... }
  SomeClass( const string& s, int i = 5) { ... }
  SomeClass( const string& s1, const string& s2, int i = 5) { ... }
};

I have though about making functions like

SomeClass
py_SomeClass_default_construct()
{
  return SomeClass();
}

SomeClass
py_SomeClass_string_construct(const string& s)
{
  return SomeClass(s);
}

SomeClass
py_SomeClass_two_string_construct(const string& s1, const string& s2)
{
  return SomeClass(s1,s2);
}

But am not sure how I would use these....

Thanks,
John Hunter


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