Re: C++ Function With Default Arguments?
H C <[email protected]> Thu, 23 Sep 2021 15:39:25 +0800
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CAGPGUd816nsWzM9Pqsc1jUrKcQS7D+g2BHpm6iu7jciGcjEhRg@mail.gmail.com> |
Hi Lluís, Yes, it works. The error message is a bit misleading. Thanks! On Thu, Sep 23, 2021 at 2:03 PM Lluís Alemany Puig < [email protected]> wrote: > You could try by adding > > %include stdint.i > > in the appropriate location in your *.i file. > > I didn't try this myself, but that's what I usually do when I use uint32_t, > int32_t, irrespective of default parameters. > > Cheers, > > L > On 23/9/21 5:30, H C wrote: > > Hi, > > I have the following C++ function in `say.hpp`: > > #include <iostream> > > > void say(const char* text, const uint32_t x = 16, const uint32_t y = > 24, const int32_t z = -1) { > std::cout << text << std::endl; > } > > > Here is my `say.i`: > > %module say > %{ > #include "say.hpp" > %} > > %include "say.hpp" > > Then, I built the shared library: > > $ swig -python -c++ -I/usr/include say.i > $ g++ -fPIC -c say_wrap.cxx > -I/opt/rh/rh-python38/root/usr/include/python3.8 > $ g++ -shared say_wrap.o -o _say.so > > Then, I tried to call it: > > >>> import say > >>> say.say("hello") > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/home/hc/test/cpp/say.py", line 66, in say > return _say.say(text, x, y, z) > TypeError: Wrong number or type of arguments for overloaded function > 'say'. > Possible C/C++ prototypes are: > say(char const *,uint32_t const,uint32_t const,int32_t const) > say(char const *,uint32_t const,uint32_t const) > say(char const *,uint32_t const) > say(char const *) > > >>> > > It seems something is wrong with having default values for the function > parameters as once I remove them, it works. > > I searched the mailing list, it seems there was a similar issue back in > 2015: > > https://sourceforge.net/p/swig/mailman/swig-user/thread/9693B382-97FB-41F2-BD0E-D5C009BA087D%40arlut.utexas.edu/#msg33340062 > > Is it the same bug? > > Thanks! > > > _______________________________________________ > Swig-user mailing [email protected]://lists.sourceforge.net/lists/listinfo/swig-user > > _______________________________________________ > Swig-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/swig-user > _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user