Witam!
Mam pewien problem z zaimplementowaniem właściwości w ISO C++. Otóż sposób w który to zrobiłem działa dobrze dla typów wbudowanych, enumów i wskaźników na nie, jednak zupełnie się nie sprawdza w przypadku struktur i klas. Czy miałby ktoś jakiś pomyśl jak to rozwiąć?
Kod mojego rozwiązania :
template <typename Type, typename Class>
class __property
{
private:
__property(const __property<Type, Class>&); // not implemented
__property<Type, Class>& operator=(const __property<Type, Class>&); // not implemented
typedef void(Class::*Set)(Type);
typedef Type(Class::*Get)();
Set __set;
Get __get;
Class* __class;
public:
operator Type()
{
return (__class->*__get)();
}
__property<Type, Class>& operator=(Type val)
{
(__class->*__set)(val);
return *this;
}
__property(Get getter, Set setter, Class* ClassPtr) : __set(setter), __get(getter), __class(ClassPtr) {}
};