I have the same problem as discussed at
The best solution there looks like this one, but I cannot get it to compile - see embedded comments. Any advice much appreciated.
The best solution there looks like this one, but I cannot get it to compile - see embedded comments. Any advice much appreciated.
Code:
template <typename T, typename C>
class Property
{
typedef T (C::*Get)() const;
typedef void (C::*Set)(T);
Get GetFunc_;
Set SetFunc_;
C & Class_;
public:
Property(Get GetFunc, Set SetFunc, C &Class)
: GetFunc_(GetFunc), SetFunc_(SetFunc), Class_(Class) {}
operator T () const
{
return (Class_.*GetFunc_)();
}
Property<T, C>& operator=(T val)
{
(Class_.*SetFunc_)(val);
return *this;
}
};
class TMyClass
{
int FMyVariable;
public:
Property<int, TMyClass> MyVariable;
// fails at the line below in an MFC compile using VS2013
// wants argument lists, so I changed to
// TMyClass() : MyVariable(GetMyVariable(), SetMyVariable(int), *this)
// but no good.
TMyClass() : MyVariable(GetMyVariable, SetMyVariable, *this)
{
}
int GetMyVariable() const
{
return FMyVariable;
}
void SetMyVariable(int Value)
{
FMyVariable = Value;
}
};
Comment