[C++-sig] Wrapping an abstract interface

Andreas Kloeckner ak at ixion.net
Sat Feb 14 15:58:26 CET 2004

Hey again, 

I have an abstract interface like this:

8< ----------------------------------------------------------------------------
class MatrixOperator
  virtual void apply(const Vector &) const = 0;
8< ----------------------------------------------------------------------------

which I want to wrap. In Python, I want to pass this function a Numeric
array.  Vector is a class that could be initialized to share data with a
Numeric array.

How would I do such a thing?

- Can I create a subclass of MatrixOperator that takes a Numeric array
  and use the class_ HeldType feature to force its use?

- Can I write a custom value converter that would to this
  Numeric.array->Vector conversion for me? How?


- Do I need to do this the "easy way", by having a separate function
  applyOperator(const MatrixOperator &,NumericArray &)?

This boils down to this: Can I make it appear from Python as if a class
has a method for which no member function in C++ actually exists (but
maybe just a regular function)?


More information about the Cplusplus-sig mailing list