【发布时间】:2011-09-11 23:06:38
【问题描述】:
我目前有这个:
#define THIS(T) (boost::static_pointer_cast<T>(shared_from_this()))
宏被用在这样的方法中:
void Derived::run() {
do_something_with_a_shared_ptr(THIS(Derived));
}
这一切都很好,但我想删除 (Derived) 并拥有:
void Derived::run() {
do_something_with_a_shared_ptr(THIS);
}
这可能吗?
或者,在从boost::enable_shared_from_this 派生(间接)的类中,是否有更好的方法可以方便地访问shared_ptr 到this? This question 似乎表明答案是否定的。
类层次结构如下所示:
class Base: public boost::enable_shared_from_this<Base> {
...
}
class Derived: public Base {
...
void run();
...
}
void do_something_with_a_shared_ptr(boost::shared_ptr<Derived>);
【问题讨论】:
标签: c++ boost shared-ptr