You have a working example as I sent you, use that approach. Your error is shown below.

2009/6/29 Rubin, Jared <JARED.RUBIN@saic.com>

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)





Foo.h
=====
template<class T> class Foo {
  public:
    T data;
  public:
  // null constructor
  Foo() {}
  Foo(T d)
  {
    data = d;

  }
};

Bar.h
=====
#include "Foo.h"
template<class T>
void Bar(T& f);


Bar.C
======
#include "Bar.h"
template<class T>
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>;

FooInt is not a C++ type, so you can't use it as a type in the C++ template. You probably intended:
%template(BarInt) Bar< Foo<int> >;

and then reorder the %include and %template as per my example so that the %template(BarInt) is declared before it is used.

William
 




Thanks
Jared















Jared



-----Original Message-----
From: william@fultondesigns.co.uk on behalf of William S Fulton
Sent: 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@fultondesigns.co.uk on behalf of William S Fulton
> Sent: Fri 6/19/2009 5:49 PM
> To: Rubin, Jared
> Cc: swig-user@lists.sourceforge.net
> 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
>