C++相談室 part10
■ このスレッドは過去ログ倉庫に格納されています
0707683
NGNG> public: ClassName x;
これだとUserの中にproperty<..User..>の中にUserの中にproperty<..User..の中に…
の無限入れ子になってしまう。C++はJavaじゃないので参照なりポインタなりは
そのむねちゃんと書かんといかんよ。
template <typename Type, class ClassName, Type (ClassName::*Getter)(), void (ClassName::*Setter)(Type)>
class property
{
private: Type m_Value;
public: ClassName& x;
public: property& operator= (Type rhs){ (x.*Setter)(rhs); return *this; }
public: operator Type() { return (x.*Getter)(); }
public: property(ClassName& owner) :x(owner){}
};
class User
{
private: int v_;
public: int Get(){ return v_; }
public: void Set(int v){ v_ = v; }
property<int, User, &User::Get, &User::Set> ValueProperty;
public: User() : ValueProperty(*this){}
};
■ このスレッドは過去ログ倉庫に格納されています