c++ - Function default parameters are ignored -


for simplified piece of code i'm getting following error:

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

int g(int = 2, int b = 1) {     return + b; }  template<class func> void generic(func f) {     std::cout << f(); }  int main() {     generic(g); } 

i cannot clue reason why default parameters of function f not passing function generic. behaves f doesn't have default parameters ...

what's wrong there?

how forward default parameters correctly?

g may have default arguments, type of &g still int(*)(int, int), not type can called no arguments. within generic, can't differentiate - we've lost context default arguments.

you can wrap g in lambda preserve context:

generic([]{ return g(); }); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -