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



10/8/2019 9:54:40 AM


5 Answers

New Answer


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).


Chirag Kumar see line with comment (//)


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 !!


jtrh I don't need it. It was in SoloLearn challenge


jtrh thanx