« Return to Thread: function template uses templated header - swig interface file
William,
The following doesn't work. Maybe you can see an obvious problem. I get the below compiler error
Bar_wrap.cxx: In function `PyObject* _wrap_BarInt(PyObject*, PyObject*)':
Bar_wrap.cxx:2866: error: `FooInt' undeclared (first use this function)public:
Foo.h
=====
template<class T> class Foo {
T data;
public:
// null constructor
Foo() {}
Foo(T d)
{
data = d;template<class T>
}
};
Bar.h
=====
#include "Foo.h"
void Bar(T& f);template<class T>
Bar.C
======
#include "Bar.h"
void Bar(T& f) {
// do something;
f.data = f.data + 1;
return;
}
Bar.i
=====
%module Bar
%{
#include "Bar.h"
%}
%include "Foo.h"
%include "Bar.h"
%template(FooInt) Foo<int>;
%template(BarInt) Bar<FooInt>;
Thanks
JaredSent: Thu 6/25/2009 10:58 AM
To: Rubin, Jared
Subject: Re: [Swig-user] function template uses templated header - swig interface file
Rubin, that post shows what to do quite clearly. Not sure what else I
can do. Try make a small standalone interface file of what you want to wrap.
William
Rubin, Jared wrote:
> William,
> Thanks for the response. I have been able to instantiate a templated
> C++ class. However I have not
> been able to get a separate templated function (that is outside the
> scope of the above C++ class) that requires
> an instance of the templated function to work. I even followed the below
> thread with no luck
>
> http://www.nabble.com/template-function-not-wrapped-td17401882.html#a17402122
> Jared
>
>
>
>
> -----Original Message-----
> From: william@... on behalf of William S Fulton
> Sent: Fri 6/19/2009 5:49 PM
> To: Rubin, Jared
> Cc: swig-user@...
> Subject: Re: [Swig-user] function template uses templated header - swig
> interface file
>
> Rubin, Jared wrote:
> > How does one create the swig interface file for a function (in a
> > separate file) that uses a templated header file?
> > My Bar.C uses a template instance of Foo.h. I am not seeing the code
> > being wrapped correctly
> > Thanks
> >
> >
> > # A function template that uses a class template
> > Foo.h
> > ==============
> > template <class T> class Foo {
> > private:
> > T* data;
> > public Foo(T *d)
> > {
> > data = t;
> > }
> > }
> >
> > Bar.h
> > =================
> > #include "Foo.h"
> > void bar(Foo<int> f);
> >
> > Bar.C
> > =================
> > #include "Bar.h"
> > void bar(Foo<int> f) {
> > // do something;
> > return;
> > }
> >
> > FooBar.i
> > =========
> > %module FooBar
> > %include "Foo.h"
> > %template(FooI) Foo<int>;
> > %include "Bar.h"
> >
> How is it not being wrapped correctly? Assuming you fix the C++ code so
> that it compiles, it should generate wrappers, although you'd have a
> SWIGTYPE_p_int type wrapper class which isn't great. See the docs for
> improving the wrapping pointers to primitive types.
>
> William
>
« Return to Thread: function template uses templated header - swig interface file
| Free embeddable forum powered by Nabble | Forum Help |