i have this code
#include <iostream>
#include <memory>
#include <vector>
using namespace std;
class Foo : public std::enable_shared_from_this<Foo> {
public:
Foo() { list_.push_back(shared_from_this()); }
private:
static std::vector<shared_ptr<Foo>> list_;
};
std::vector<shared_ptr<Foo>> Foo::list_;
int main() {
Foo f;
cout << "Hello World!" << endl;
return 0;
}
but i get following error
terminate called after throwing an instance of 'std::bad_weak_ptr'
what(): bad_weak_ptr
Press <RETURN> to close this window...
so how can i add to list_
when i construct a class without call external function after initilization?