[C++-sig] using function objects as getters/setters for the properties
Gennadiy Rozental
rogeeff at gmail.com
Tue Feb 10 22:48:13 CET 2009
Hi,
I need to implement some translation in a getter and setter for particular field.
I am getting compile time errors, I am not sure how to fix. I am using 1.33.1.
Here is what I do:
template<typename T>
struct Getter {
explicit Getter( MyClass T::* mem ) : m_member( mem ) {}
bp::object operator()( T const& obj ) const
{
return /* conversion here */;
}
MyClass T::* m_member;
};
template<typename T>
Getter<T>
make_getter( MyClass T::* mem )
{
return Getter<T>( mem );
}
....
bp::class_< MyClass >( "MyClass", bp::no_init )
.add_property( "field", make_getter( &MyClass::field ) )
I see following errors:
..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(441) : error C2784:
'boost::mpl::vector17<RT,most_derived<Target,ClassT>::type&,
T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>
boost::python::detail::get_signature(RT (__thiscall ClassT::*
)(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14)
volatile const,Target *)' :
could not deduce template argument for 'T2 (__thiscall T3::*
)(T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18)
volatile const' from 'const Getter<T>'
with
[
T=MyClass
]
..\..\3rdParty\boost-1.33.1\boost\python\signature.hpp(164):
see declaration of 'boost::python::detail::get_signature'
..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(424):
see reference to function template instantiation
'boost::python::api::object boost::python::class_<W>::
make_fn_impl<W,F>(T *,const F &,boost::mpl::false_,void *,
boost::mpl::false_)' being compiled
with
[
W=MyClass,
F=Getter<MyClass>,
T=MyClass
]
..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(308):
see reference to function template instantiation
'boost::python::api::object boost::python::class_<W>::
make_getter<Get>(F)' being compiled
with
[
W=MyClass,
Get=Getter<MyClass>,
F=Getter<MyClass>
]
src\export_riskmgr.cpp(157): see reference to
function template instantiation 'boost::python::class_<W>::self
&boost::python::class_<W>::add_property<Getter<T>>
(const char *,Get,const char *)' being compiled
with
[
W=MyClass,
T=MyClass,
Get=Getter<MyClass>
]
..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(441):
error C2780:
'boost::mpl::vector17<RT,ClassT&,
T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>
boost::python::detail::get_signature(RT (__thiscall ClassT::*
)(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14)
volatile const)' : expects 1 arguments - 2 provided
..\..\3rdParty\boost-1.33.1\boost\python\signature.hpp(146) :
see declaration of 'boost::python::detail::get_signature'
..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(441):
error C2784:
'boost::mpl::vector17<RT,most_derived<Target,ClassT>::type&,
T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>
boost::python::detail::get_signature(
RT (__thiscall ClassT::* )
(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14)
volatile,Target *)' : could not deduce template argument for
'T2 (__thiscall T3::* )
(T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18)
volatile' from 'const Getter<T>'
with
[
T=MyClass ]
..\..\3rdParty\boost-1.33.1\boost\python\signature.hpp(164) :
see declaration of 'boost::python::detail::get_signature'
And lots more like this. I've tried to add make_function around. Did not help.
Any pointers? Thanks.
Gennadiy
More information about the Cplusplus-sig
mailing list