Boost logo

Boost :

From: charlie_at_[hidden]
Date: 2001-03-21 14:44:57


If I am exposing these 2 simple classes to Python:

  class point
  {
  public:
          float x, y;
  };

  class quad
  {
          point p1;
  public:
          void add(const point& p) { p1 = p; }
          point& get() { return p1; }
  };

... with this code:

        python::class_builder<point> point_class
(this_module, "point");
        point_class.def(python::constructor<>());
        point_class.def_read_write(&point::x, "x");
        point_class.def_read_write(&point::y, "y");

        python::class_builder<quad> quad_class(this_module, "quad");
        quad_class.def(python::constructor<>());
        quad_class.def(&quad::add, "add");
        quad_class.def(&quad::get, "get");

... should there be a simple change that allows this to work:

>>> p = point()
>>> p.x = 100
>>> p.y = 125
>>> q = quad()
>>> q.add(p)
>>> q.get().x = 0
>>> q.get().x
0.0

^ instead it's returning 100.0 (because the get() is returning a copy
of the point p).

Thanks!

Charlie Barrows


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk