c++ - Returning reference to a function template -
i have template class called managed has static templated create() function. i'm trying write helper returns function when passed 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 takes template arguments, explicitly try reference instantiation takes windowbase&. far can see above code should work.
however, when try call it, following error:
error: expected '(' function-style cast or type construction screenfactory ret = &t::create<windowbase&>; ~~~~~~~~~~^ i'm not sure i'm doing wrong, pointers?
you missing template keyword:
template<typename t> screenfactory screen_factory() { screenfactory ret = &t::template create<windowbase&>; // ~~~~~~~^ return ret; } for details please refer where , why have put “template” , “typename” keywords?
Comments
Post a Comment