Using shared_from_this in templated classes

enable_shared_from_this<manager<Policy>> is a “dependent base” (it’s a base class whose type depends on a template parameter, in this case Policy) so the rules of C++ say that unqualified name lookup doesn’t look in there, you need to say this->shared_from_this() or std::enable_shared_from_this<manage<Policy>>::shared_from_this() to find the member from the dependent base.

See http://gcc.gnu.org/wiki/VerboseDiagnostics#dependent_base for more detail and links to other references.

To fix the second error you need to make enable_shared_from_this a public base class, or it can’t get initialized when the manager is owned by a shared_ptr.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)