[C++-sig] a few questions about properties

Roman Yakovenko romany at actimize.com
Mon Aug 4 09:36:43 CEST 2003


Hi. For all question I will introduce here I find solution.
But I don't fill good with them. 
 So...


struct CConst
{
private:

    explicit CConst( int i ) : m_value(i){};

public:

    const static CConst const_1;
    const static CConst const_2;

    int get_value() const { return m_value; }

    const int& get_value_by_ref() const { return m_value; }

private: 

    int m_value;
};

const CConst CConst::const_1(1);
const CConst CConst::const_2(2);

const CConst& get_const_1() { return CConst::const_1; }
const CConst& get_const_2() { return CConst::const_2; }

BOOST_PYTHON_MODULE(py_smart_const)
{
    class_<CConst>( "CConst", no_init )
        .add_property( "value", &CConst::get_value )
        //error .add_property( "value", &CConst::get_value_by_ref )
        .def( "const_1", &get_const_1, return_value_policy< reference_existing_object >() )
        .staticmethod("const_1")
        .def( "const_2", &get_const_2, return_value_policy< reference_existing_object >() )
        .staticmethod("const_2");
}

The first question is how can I add class property? 
	In my example I write 2 functions get_const_1 and get_const_2
	and also I get staticmethod and not class property.

The second one is how can I specify property return value policy?
      In my example .add_property( "value", &CConst::get_value_by_ref ) will not compile
	with error specify_a_return_value_policy_to_wrap_functions_returning. 

I think that there is no special reason ( except luck of time ), am I right?

Thanks. 
	Roman.





More information about the Cplusplus-sig mailing list