+2

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

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

c++

10/8/2019 9:54:40 AM

UraL

5 Answers

New Answer

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

+2

Chirag Kumar see line with comment (//)

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

0

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

0

jtrh thanx