私はこのslidesをチェックし、まだ取得していない:なぜQuantLibはHandleクラスを導入しましたか?
1) what problem does Handle sovled?
2) what is the benefit to add the Handle class?
そのソースコードから、私はどちらか任意の手掛かりを得ることができません。
template <class Type>
class Handle {
protected:
class Link : public Observable, public Observer {
public:
explicit Link(const shared_ptr<Type>& h =
shared_ptr<Type>());
void linkTo(const shared_ptr<Type>&);
bool empty() const;
void update() { notifyObservers(); }
private:
shared_ptr<Type> h_;
};
boost::shared_ptr<Link<Type> > link_;
public:
explicit Handle(const shared_ptr<Type>& h =
shared_ptr<Type>());
const shared_ptr<Type>& operator->() const;
const shared_ptr<Type>& operator*() const;
bool empty() const;
operator boost::shared_ptr<Observable>() const;
};
template <class Type>
class RelinkableHandle : public Handle<Type> {
public:
explicit RelinkableHandle(const shared_ptr<Type>& h =
shared_ptr<Type>());
void linkTo(const boost::shared_ptr<Type>&);
};
は、誰かがより良い例を挙げてもらえますか?
ありがとうございました。
ご清聴ありがとうございます、ルイージ! – camino
ご清聴ありがとうございます。これに関するもう1つの質問。クラスリンクは何をし、リンクのコンストラクタに渡された共有ポインタhについてどう考えるべきですか? – user1559897
リンク内の 'shared_ptr'は、現在ポイントされているオブジェクトです。 'Link'クラスはそれの上にオブザーバビリティを追加して、先のオブジェクトが変わったときに通知を受け取ります。 –