The first problem can be solved with std::enable_shared_from_this, which allows you to safely create a shared pointer instance from within class A.
The second problem may be solved by using a static factory method belonging to class A
and not using std::make_shared like this:
static std::shared_ptr<A> create() {
return std::shared_ptr<A>(new A());
}
Then, you can make A
's constructor private.