0

I found this:

template<typename Ret, typename ...Args>
class Function {
public:
    Function(Ret (*func)(Args...)): func(func) {};

    Ret operator()(const Args& ...args) {
        return func(args...);
    }

private:
    Ret (*func)(Args...);
};

void sayHello() {
    std::cout << "hello" << std::endl;
}

int main() {
    Function<void> fn(sayHello);
    fn();
}

If I didn't provide types in the first line in the main function, it will be compile error. But, isn't the types able to be infered according to the argument of the constructor?

Luminous
  • 39
  • 1
  • 3
  • It works since C++17. But I can't check it because the code is not compilable due to missing #include directives and I'm lazy for much editing the code. – 273K Apr 18 '22 at 23:58

0 Answers0