나는이 slides을 확인하지만 여전히하지 않았다 :왜 QuantLib에서 Handle 클래스를 도입 했습니까?
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>&);
};
사람이 더 나은 예를 들어 줄 수 :
소스 코드에서1) what problem does Handle sovled?
2) what is the benefit to add the Handle class?
, 나는 어떤 단서 중 하나를 얻을 수 없다?
감사합니다.
루이지 귀하의 명확한 설명에 감사드립니다. – camino
설명해 주셔서 감사합니다. 이것에 대한 또 하나의 질문입니다. 클래스 링크는 무엇을하고 링크의 생성자에 전달 된 공유 포인터에 대해 어떻게 생각해야합니까? – user1559897
링크의'shared_ptr '은 현재 가리키는 객체입니다. 'Link' 클래스는 그 위에 관찰 가능성을 추가하여 뾰족한 객체가 변경 될 때 알림을 얻습니다. –