[C++-sig] Re: Construct for c++ class with reference

Neal D. Becker ndbecker2 at verizon.net
Tue Apr 20 19:34:29 CEST 2004

David Abrahams wrote:

> "Neal D. Becker" <ndbecker2 at verizon.net> writes:
>> How should I wrap this (simplified example):
>> struct X {
>>   X (int& _x) : x (_x) {}
>>   int& x;
>> };
> References to builtins are a difficult case.  If it were a class you
> could use a read_write property.  Python ints are immutable, so you
> have to decide how you'd like to see this translated.  What do you
> want the Python interface to be?

Actually, I wanted to use this with a class.  This code is meant to wrap
boost random number stuff.  I acutally found an answer by asking pyste. 
This code seems to work:

  class_<boost_normal_wrap> ("normal", init<const boost_normal_wrap&>())
    .def (init<rng_t&, double>())
    .def ("Compute", &boost_normal_wrap::Compute)

I got runtime error if I tried it like this (from memory, hope I got this

  class_<boost_normal_wrap> ("normal", init<rng_t&, double>())
    .def ("Compute", &boost_normal_wrap::Compute)

I don't acually know why #1 works and #2 doesn't.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: boost_rand.cc
Type: text/x-csrc
Size: 1182 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20040420/a9a82b15/attachment.c>

More information about the Cplusplus-sig mailing list