From: Stefan Z. <sz...@gm...> - 2011-10-31 21:57:48
|
On Mon, Oct 31, 2011 at 1:51 PM, Marco Correia <mar...@gm...> wrote: > Hi Stefan, > > Thank you for your reply. > > I'm afraid I don't agree with you. There are two separate classes with > different methods which I want to wrap. One is Expr<int>, which I want to wrap > as IntExpr, and another is Expr<Seq<int>> which I want to wrap as IntSeqExpr. Sorry, my mistake -- I didn't look closely enough at the error output. I agree that this is incorrect behavior, and I suggest you file a bug. Having said that, keep in mind that SWIG doesn't claim to do 100% faithful processing of templates. The usage in your example is a bit esoteric, so I can't say for certain that anyone will volunteer to fix it. You may be able to work around it by putting something like this in your interface, before the class declarations: %ignore Expr<Seq<int> >::method1; Stefan > > It happens in this example that IntExpr and IntSeqExpr have a different set of > methods, which is no problem to SWIG if they were coming from unrelated > classes. In this case they correspond to two specializations of a single > template, and, in my opinion, they should be treated as different classes also. > Templates are used to expand source code, there is nothing related to > inheritance here. > > Thanks again > Marco > > On Monday 31 October 2011 20:42:59 you wrote: >> I think the error is in your code, not in swig. The rules of template >> specialization dictate that method1 is *not* defined for Expr<Seq<int> >> >> > as you have written it. I think you may be confusing inheritance >> >> with template specialization. >> >> Hope that helps. >> >> Stefan >> >> On Mon, Oct 31, 2011 at 8:12 AM, Marco Correia >> >> <mar...@gm...> wrote: >> > I think I found a bug. Consider the following example module called >> > mytest: >> > >> > %module mytest >> > %inline %{ >> > >> > template<class T> struct Seq; >> > >> > template<class E> >> > struct Expr >> > { >> > Expr() {} >> > void method1() { } >> > }; >> > >> > template<class E> >> > struct Expr<Seq<E> > >> > { >> > Expr() {} >> > void method2() { } >> > }; >> > >> > %} >> > >> > %template(IntExpr) Expr<int>; >> > %template(IntSeqExpr) Expr<Seq<int> >; >> > >> > Compiling gives: >> > >> > swig -o mytest_wrap.cpp -c++ -python mytest.i >> > ok. >> > >> > g++ -o mytest_wrap.os -c -g3 -O0 -Wall -fPIC -I/usr/include/python2.7 >> > mytest_wrap.cpp >> > >> > errors: >> > mytest_wrap.cpp: In function ‘PyObject* >> > _wrap_IntSeqExpr_method1(PyObject*, PyObject*)’: >> > mytest_wrap.cpp:2896:11: error: ‘struct Expr<Seq<int> >’ has no member >> > named ‘method1’ >> > >> > It seems that SWIG is not finding the proper template specialization. I'm >> > attaching the source mytest.i. >> > >> > Thanks! >> > Marco >> > >> > -- >> > Marco Correia <mv...@ne...> >> > >> > ------------------------------------------------------------------------- >> > ----- Get your Android app more play: Bring it to the BlackBerry PlayBook >> > in minutes. BlackBerry App World™ now supports Android™ Apps >> > for the BlackBerry® PlayBook™. Discover just how easy and >> > simple it is! http://p.sf.net/sfu/android-dev2dev >> > >> > _______________________________________________ >> > Swig-user mailing list >> > Swi...@li... >> > https://lists.sourceforge.net/lists/listinfo/swig-user > > -- > Marco Correia <mv...@ne...> > |