+ 2

Can I declare pointer to function with default parameters? If can, the how?

https://code.sololearn.com/c113l1QsG3ZI/?ref=app

8th Oct 2019, 9:54 AM
UraL
5 Answers
+ 2
https://en.cppreference.com/w/cpp/language/default_arguments "Default arguments are only allowed in the parameter lists of function declarations and lambda-expressions, (since C++14) and are not allowed in the declarations of pointers to functions, references to functions, or in typedef declarations." I don't know what you need this for but you could make them overloads and have 2 function pointers/1 function pointer then cast to the overloaded type, or use a lambda/functor/another function that takes a default parameter that invokes your function through the function pointer (I don't see the point of doing this).
8th Oct 2019, 10:27 AM
jtrh
jtrh - avatar
+ 2
Chirag Kumar see line with comment (//)
8th Oct 2019, 10:35 AM
UraL
+ 1
UraL ohh ok didn't notice that. I think you cant. I don't know the perfect explanation so can't help :) But others will guide you !!
8th Oct 2019, 10:38 AM
Chirag Kumar
Chirag Kumar - avatar
0
jtrh I don't need it. It was in SoloLearn challenge
8th Oct 2019, 10:38 AM
UraL
0
jtrh thanx
8th Oct 2019, 10:39 AM
UraL