I've defined a class template and a function,
template <typename F> class Base {
public:
Base(F ff): f(ff) {}
template <typename... Ps> auto operator() (Ps... ps) const -> decltype(f(ps...)) { return f(ps...); }
private:
// f is a pointer to function
F* f;
};
int f(int i, int j)
{
return i + j;
}
int main()
{
using f_type = remove_reference<decltype(f)>::type;
Base<f_type> b{f};
b(2, 5); // [Error] no match for call to '(Base<int(int, int)>) (int, int)'
}
the labeled error was reported. But when I changed the order of member variable of
class Base
, like:
template <typename F> class Base {
private:
// f is a pointer to function
F* f;
public:
Base(F ff): f(ff) {}
template <typename... Ps> auto operator() (Ps... ps) const -> decltype(f(ps...)) { return f(ps...); }
};
It can compile.
What's the reason of these two different results? Thank you for your time!