[C++-sig] Derived C++ types in Python

Brian Hall bhall at gamers-fix.com
Sun Sep 12 03:08:54 CEST 2004


Hello all,

Do C++ types in python automatically get cast to the most specific type as
they cross the python barrier?  I know this code below isn't quite right,
but I'm just trying to illustrate the concept.


class A
{
 int doSomething();
};

class B : public A
{
 int doSomethingElse();
}

class C
{
  int doSomethingElseEntirely();
  void fillPtr() { myptr = new B; }
  A* myptr;
}

// python class
class D(C):
   def __init__(self):
      self.fillPtr()

   def anotherfunc(self):
      self.myptr.doSomethingElse()

Assuming I have something like the classes above, and assuming they've all
been properly exposed.  If my python class D had its myptr member
initialized on the C++ side with a class B instance, would the python side
know about it?  Would the exposed myptr member have access to all of the
exposed methods on the derived type?

Thanks!

Brian Hall

 





More information about the Cplusplus-sig mailing list