the following works as expected:
template<typename... Types>
auto countNumberOfTypes() { return sizeof...(Types); }
template<typename... Types>
consteval auto functionReturnsFunction() { return countNumberOfTypes<Types...> };
functionReturnsFunction<int, const double>()() == 2;
but the following does not even compile:
struct Test
{
template<typename... Types>
auto countNumberOfTypes() { return sizeof...(Types); }
};
template<typename... Types>
consteval auto functionReturnsFunction2() { return &Test::countNumberOfTypes<Types...>; }
// functionReturnsFunction2<int, const double>()() == 2;
error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘&Test::countNumberOfTypes (...)’, e.g. ‘(... ->* &Test::countNumberOfTypes) (...)’
29 | if (functionReturnsFunction2<int, const double>()() == 2)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
...any suggestions?
Test, you need an object of typeTest. There is no such object infunctionReturnsFunction2<int, const double>()(). How do you expect this to work?(Test{}.*functionReturnsFunction2<int, const double>())() == 2.e.g. ‘(... ->* &Test::countNumberOfTypes) (...)’it's telling you what you should have written.(something->*&Test::countNumberOfTypes)(something)- how would you recommend improving the error message?