I\'m just toying around with the smart pointers in the upcoming new c++ standard. However I fail to grasp the usage of the shared_from_this function. Here is what I have:
To extend Charles answer, when you use enable_shared_from_this
you usually want something like below in order to guarantee that there exists a shared_ptr.
class my_class : public std::enable_shared_from_this
{
public:
static std::shared_ptr create() // can only be created as shared_ptr
{
return std::shared_ptr(new my_class());
}
private
my_class(){} // don't allow non shared_ptr instances.
};