Hi,
I have been trying to use shared_ptr but after searching the net and reading example, I still don't understand how to use std::shared_ptr?
Say, I have a class -
class foo
{
public:
foo();
~foo();
void init();
}
Now I want to use this in another class -
class useme
{
public:
useme();
~useme();
void init();
private:
std::shared_ptr<foo> f1;
std::list<shared_ptr<foo>> foolist;
}
In init() method, how do I create the f1 and push_back it into foolist?
I tried like this -
foolist.push_back(std::shared_ptr<foo>(new foo()));
or
f1 = std::make_shared<foo>(new foo());
foolist.push_back(f1);
Any help will be appreciated. Thanks in advance.