C++ Function With Default Arguments?

H C <[email protected]> Thu, 23 Sep 2021 11:30:36 +0800
Newsgroups gmane.comp.programming.swig
Message-ID <CAGPGUd_U4Br38NKN2F9aPADKoSrxw4TTk7UfVPZn2it1=axmOA@mail.gmail.com>
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 list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user