From: William S F. <ws...@fu...> - 2007-11-02 22:46:37
|
debutant wrote: > Hello, > > I have a problem when trying to wrapp the following piece of C++ code. > It is just a simple example that shows the problem I have. My question > will appear after. > > ***************** > #include <iostream> > > template<class T> > class Base_const > { > public: > void print_Base_const() > {std::cout<< " print from Base_const \n";} > }; > > template <class T> > class Base_unconst > { > public: > void print_Base_unconst() > {std::cout<< " print from Base_unconst \n";} > }; > > template <class T> class Concrete; > > template <class T> > class Concrete<const T> : public Base_const<const T> > { > public: > void print_Concrete_const() > {std::cout<< " print from Concrete_const \n";} > }; > > template <class T> > class Concrete : public Base_unconst<T> > { > public: > void print_Concrete() > {std::cout<< " print from Concrete \n";} > }; > > ***************** > In C++, I can do without problems: > int main() > { > Concrete<int> concrete; > concrete.print_Concrete(); > concrete.print_Base_unconst(); > Concrete<const int> concrete_const; > concrete_const.print_Concrete_const(); > concrete_const.print_Base_const(); > } > > But I don't know how to wrappe that code with swig. > If I write: > %template(Concrete_sizet) Concrete<size_t>; > swig will wrapp the class: > template <class T> class Concrete : public Base_unconst<T> > in the right way. > But I don't know what to do about: > template <class T> class Concrete<const T> : public Base_const<const T> > > I tried: > %template(Concrete_constsizet) Concrete<const size_t>; > but it does not work .... > > Thank you in advance for any suggestions. > Sincerely, > Michel Firstly, put the %template directives for the base classes after the base class declarations and before SWIG parses the Concrete declarations. %template(Base_const_sizet) Base_const<const size_t>; %template(Base_unconst_sizet) Base_unconst<size_t>; the put the %template for Concrete after the declaration of Concrete. However, I can't get this to work either as SWIG is getting confused by the partial template specializations. Can you please log as a bug in the bug tracker. I suspect SWIG is not expecting for class specializations and it just uses the first one it finds. You will be able to trick SWIG into working by putting one of the specializations into a different C++ namespaces. William |