Why can’t I use alias from a base class in a derived class with templates?

Unqualified lookup does not look in dependent base classes in class templates.

So here:

template <typename Socket>
class StartSession : public Step<Session<Socket> >
{
protected:
   Session_ptr m_session; // <== unqualified name lookup on Session_ptr
   // ...
};

Step<Session<Socket>> is a dependent base class of StartSession<Socket>. In order to lookup there, you’ll have to do qualified name lookup (which is what you’re doing in StartSession2):

template <typename Socket>
class StartSession : public Step<Session<Socket> >
{
protected:
   typename Step<Session<Socket>>::Session_ptr m_session;
   // ...
};

Or simply add the alias yourself:

using Session_ptr = typename Step<Session<Socket>>::Session_ptr;

Leave a Comment