I have a class
class Consumer
{
public:
typedef std::function<void()> EventHandler;
...
};
which I would like to use in this as template
template<class Consumer>
class ConsumerGroup
{
public:
typename Consumer::EventHandler EventHandler;
ConsumerGroup(EventHandler handler);
};
But above one results compilation error saying EventHandler is not a type. How should I use typename keyword in this case?
You need a type alias for dependent Consumer::EventHandler
.
This should work:
using EventHandler = typename Consumer::EventHandler;
for lower compiler versions(before C++11)
typedef typename Consumer::EventHandler EventHandler;