i’ve got a function declaration in c++ and need to know how it’s working:
template<class x>
int fun(x, x(*)(x*) );
The first arg is an object of type x. And how to describe the second one?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is the declaration of a template function that returns an integer and takes, as parameters, an
xand a pointer to a function that returns anxand takes, as a parameter, anx*.The part
x(*)(x*)is the part that means “a pointer to a function that returns anxand takes, as a parameter, anx*“. The firstxis the return type, the(*)indicates that it is a pointer to a function (if the parameter had a name, it would be writtenx(*argname)(x*)), and the thirdx*is just the argument.Calling it would look like this:
Or more generally
It will not work in C because, as Daniel White said in a comment, C doesn’t have templates.