From: Willis C. <wc...@pd...> - 2011-02-17 22:26:09
|
Got it working with "compactdefaultargs". Thanks Josh. -----Original Message----- From: Josh Cherry [mailto:jc...@nc...] Sent: Thursday, February 17, 2011 10:30 AM To: Willis Cheung Cc: swi...@li... Subject: Re: [Swig-user] Wrapping of C++ method with one default argument for python On Thu, 17 Feb 2011, Willis Cheung wrote: > I have had couple methods taking in multiple default arguments which swig > wrapped into several overloaded methods, which worked fine. However, for a > C++ method with single default argument like the following: > > void Foo(Foo2 f = 0) > > it gets wrapped as two overloaded methods as well in the .cxx created by > swig, one calling Foo() and the other calling Foo(Foo2), which looks fine. > In the swig generated python source file however, I see the following: > > def Reset(self, f = 0): return _Python.Foo(self, f) > > This would seem to always generate the dispatch to call the Foo(Foo2) method > in C++. As a result, I would get "NotImplementedError: Wrong number or type > of arguments for overloaded function 'Foo'" if I try to call Foo() in > python. I presume that "Reset" should be "Foo". I imagine the problem has nothing to do with the number of (default) arguments. Rather, it has to do with the fact that the C++ default depends on an implicit conversion of 0 to a Foo2, which doesn't carry over to Python (unless you do something to enable it). You may be able to get around this by using the "compactdefaultargs" feature: http://www.swig.org/Doc2.0/SWIGPlus.html#SWIGPlus_default_args Josh |