I'm trying out an implementation of a simple property system for C++ which I found here.
But the code won't compile.
template <class T, class Object, typename T (Object::*real_getter)()>
class ReadOnlyProperty
{
Object * my_object;
public:
void operator () ( Object * obj )
{
my_object = obj;
}
T operator()() const
{
return (my_object->real_getter)();
}
T get() const
{
return (my_object->real_getter)();
}
void set( T const & value );
operator T() const {
return (my_object->*real_getter)();
}
typedef T value_type;
};
I get multiple errors at the very first line. I'm using Xcode 4 and neither LLVM 2.1 or GCC 4.2 can compile this. What's the problem?
operator=
to 'reseat' your proxy rather thanoperator()
. Or using a named member (providing it along is also common), e.g.reset
is commonly used for smart pointers.