2009/4/8 Michał Nowotka <mmm...@gmail.com>: > Hello, Good evening
> I want to expose following classes: > > class A > { > public: > A(int a, int b) > :a_(a),b_(b) > {} > int a_; > int b_; > > int compute(){return a_ + b_;} > > }; > > class C : public A > { > > public: > > C(int a, int b) > :A(a,b){} > }; > > struct TypeExposer // I have to add this class, otherwise Py++ won't > expose std::deque<C> - why? > { > typedef std::deque<C> CDeque; > CDeque deq; > }; You can read the following documents: http://language-binding.net/pyplusplus/documentation/how_to/templates.html?highlight=templates http://language-binding.net/pyplusplus/documentation/how_to/hints.html?highlight=templates The short answer: gccxml doesn't dump information about template classes, so you need to instantiate it. > class F : public std::deque<C> > { > public: > F(){} > int dlugosc() {return this->size();} > }; I am not sure how well Py++ support this use case ( deriving from std container ). I never had it. > In order to expose I use Py++ with indexing_suite_version = 2 > parameter. Py++ generates code for boost.python without any warnings > and generated code compiles well. > But then in python I get TypeError: > > import test > c = test.C(2,3) > f = test.F() > f.append(c) > f[0] > > this causes: > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: No to_python (by-value) converter found for C++ type: C > > When class C is base class everything works well. What should I change > to get this code working with derived classes? I created the following test case and it works: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1699 I tested it on Wndows, VS 2003, using pygccxml and Py++ SVN version and boost version 1.37. I believe the same code will work on Linux too. Can you verify this? > And another problem - why do I have to define TypeExposer class? Now i > must define it because otherwise Py++ won't expose std::deque<C>. But > IMO it should notice that F dirives from std::deque<C> so > std::deque<C> must be exposed... I don't see the TypeExposer definition. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig