Re: SWIG syntax error on list initializer of template ctor parameter
William S Fulton <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANGqftDH3agvGe=1dPux2AvNx_mnd57wDr=6yf=U59WQXVVTwg@mail.gmail.com> |
On Wed, 30 Sep 2020 at 18:15, <[email protected]> wrote: > > You can work around it by declaring your variable using this syntax > instead: > > > > const A<char, 3> A3 = A(std::array<char, 3>{'A','B','C'}); > > Trying that gets me: > > ``` > AJAVA_wrap.cxx: In function 'jlong Java_exampleJNI_A3_1get(JNIEnv*, > jclass)': > AJAVA_wrap.cxx:242:15: error: no matching function for call to 'A<char, > 3>::A()' > A< char,3 > result; > ^~~~~~ > ``` > > AJAVA_wrap.cxx lines 240-249: > > ``` > SWIGEXPORT jlong JNICALL Java_exampleJNI_A3_1get(JNIEnv *jenv, jclass > jcls) { > jlong jresult = 0; > A< char,3 > result; > > (void)jenv; > (void)jcls; > result = (A< char,3 >)A3; > *(A< char,3 > **)&jresult = new A< char,3 >((const A<char, 3> &)result); > return jresult; > } > ``` > SWIG needs to parse the definition of A otherwise it doesn't know there is no default constructor, so change A.i to: %{ #include "A.h" %} %include "A.h" and make the suggested change for A3. Then the generated code is: SWIGEXPORT jlong JNICALL Java_exampleJNI_A3_1get(JNIEnv *jenv, jclass jcls) { jlong jresult = 0 ; A< char,3 > *result = 0 ; (void)jenv; (void)jcls; result = (A< char,3 > *)&A3; *(A< char,3 > **)&jresult = result; return jresult; } If using c++14 or earlier, you'll need the template parameters: const A<char, 3> A3 = A<char, 3>(std::array<char, 3> {'A','B','Z'}); William _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user