[C++-sig] Tutorial

David Abrahams dave at boost-consulting.com
Thu Oct 24 20:06:56 CEST 2002


chuzo okuda <okuda1 at llnl.gov> writes:

> I read some of the tutorial. 
> 
> I cannot make it work without eliminating "const" in Class Data Members
> topic.
> How to make it work with const?
> 
> struct Var {
>    Var(std::string name) : name(name), value() {}
>    std::string const name;
>    float value;
> };
> 
> BOOST_PYTHON_MODULE_INIT(mytest3)
> {
>    using namespace boost::python; 
> 
>    class_<Var>("Var", init<std::string>())
>       .def_readonly("name", &Var::name)
>       .def_readwrite("value", &Var::value)
>       ;
> }
> 
> *** snips ***
> "boost::python::detail::copy_non_const_reference_expects_a_non_const_          
> reference_return_type<boost::add_reference<boost::add_const<boost::py          
> thon::objects::make_holder<1>::apply<boost::python::objects::detail::          
> select_value_holder<Var, Var>::type,
> *** snips ***

This was answered already, here:

   http://aspn.activestate.com/ASPN/Mail/Message/1397291

> Also, on the next topic, Class Property, I see:
> 
>     class_<Num>("Num")
>              .add_property("rovalue", &Var::get)
>              .add_property("value", &Var::get, &Var::set);
> 
> It should be &Num::get and &Num::set.

Thanks. Joel, would you make this fix?

> Additionally, I would like to have a index page that can quickly
> find information such as "add_property", "def_readonly", etc.  It
> would be very much helpful like python web page.  

Yeah, that would be nice, but it's a big job. We're looking into how
to get a tool called Synopsis to help with some of that. It's a
long-term solution, though.

-- 
                    David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com

Building C/C++ Extensions for Python: Dec 9-11, Austin, TX
http://www.enthought.com/training/building_extensions.html





More information about the Cplusplus-sig mailing list