In my project i would like to make ever object I being organized with an smart_ptr. Now if a class method returns a pointer to itself, how can i deal with this using smart_pointers correctly?
class bar{
public:
std::shared_ptr<bar> foo(){std::shared_ptr<bar>(this);}
};
int main()
{
auto a = std::make_shared<bar>();
auto b = a->foo();
std::cout << a.use_count() << std::endl; //outputs 1
}
Aucun commentaire:
Enregistrer un commentaire