Function default parameters are ignored

Viewed 975

For this simplified piece of code I'm getting following error:

error: too few arguments to function std::cout << f();

int g(int a = 2, int b = 1)
{
    return a + b;
}

template<class Func>
void generic(Func f)
{
    std::cout << f();
}

int main()
{
    generic(g);
}

I cannot clue the reason for why the default parameters of function f are not passing into a function generic. It behaves like f doesn't have any default parameters ...

What's wrong there?

How do I forward default parameters correctly?

2 Answers
Related