i've managed to create some preperty class with all the thing we expect from one. I mean when using it you don't need to call functions just using operator =
will do all the work. but there is only one thing I guess it would be nice if we could resolve :
template <class T, class X,void (T::*setFunc)(const X&),const X& (T::*getFunc)()const> class property
{
T* const owner;
X data;
friend T;
property(T*const pOwner) : owner (pOwner)
{
}
public:
property& operator = (const X& input){(owner->*setFunc)(input);return *this;}
operator const X&()const {return (owner->*getFunc)();}
};
struct c
{
protected:
void setInt(const int& data);
const int& getInt() const;
public:
c();
property<c, int ,&setInt,&getInt> myInt;
};
c::c() : myInt(this)
{
}
void c::setInt(const int& data)
{
myInt.data = data;
}
const int& c::getInt() const
{
return myInt.data;
}
see class property has 4 arguments and the first argument is the class type itself. I'd like to know if we could possibly do anything to extract class type from two function pointers property needs. somwthing like property <int, &setInt, &getInt> myInt;
.
do you know any way to eliminate first template parameter?