0

I have a template class called Managed which has a static templated create() function. I'm trying to write a helper which returns that function when passed the Managed subclass type.

typedef std::function<ScreenBase::ptr (WindowBase&)> ScreenFactory;

template<typename T>
ScreenFactory screen_factory() {
    ScreenFactory ret = &T::create<WindowBase&>;
    return ret;
}

Because create itself takes template arguments, I explicitly try to get a reference to the instantiation that takes a WindowBase&. As far as I can see the above code should work.

However, when I try to call it, I get the following error:

error: expected '(' for function-style cast or type construction
ScreenFactory ret = &T::create<WindowBase&>;
                               ~~~~~~~~~~^

I'm not sure what I'm doing wrong, any pointers?

Kazade
  • 1,297
  • 2
  • 15
  • 25

1 Answers1

4

You are missing a template keyword:

template<typename T>
ScreenFactory screen_factory() {
    ScreenFactory ret = &T::template create<WindowBase&>;
    //                      ~~~~~~~^
    return ret;
}

For details please refer to Where and why do I have to put the “template” and “typename” keywords?

Community
  • 1
  • 1
Piotr Skotnicki
  • 46,953
  • 7
  • 118
  • 160