I’m trying to convert a C++ function with std::string reference to C#.
My API looks like this:
void GetStringDemo(std::string& str);
Ideally I would like to see something like this from C#
void GetStringDemoWrap(ref string);
I understand I need to create a typemap for this, and I tried a few things by playing around with the std_string.i file, but I don’t think I’m getting anywhere. Does anyone has any example. I’m new to both Swig and C# so I’m not able to come up with any genuine ideas.
Just in case somebody is looking for this in the future, I created std_string.i like this for C#. Seems to work for me. Note that I changed the ref to out since it was more appropriate in my case but ref should work as well.
I called %include “std_string.i” from the .i file
The reason I need to define argout for const std::string& is because SWIG will get confused and override const std::string& also with the typemap. So I explicitly tell it not to override in my case (You may have a different use case)
For Python I created something like this: