+ 1

How to call one function which has a function as a parameter in main()?

Example We define a function: string month_convert(string month2, string month_fun(int& month)){}. And now I don't know how to call this function in main. Does anybody has any idea? https://code.sololearn.com/cS3W2egl3CEN/?ref=app https://code.sololearn.com/cuW1bgV4jC3J/?ref=app

10th Mar 2021, 8:12 PM
TeaserCode
6 odpowiedzi
+ 3
Martin Taylor Why would the declaration for month_convert() be invalid? In C++, I think the following are equivalent, at least when specifying a function as parameter: string month_fun( int& ) string ( *month_fun )( int& ) string ( &month_fun )( int& ) Then again, I usually use template parameters for callables. I found it suggested here: https://ncona.com/2019/05/passing-functions-as-arguments-in-cpp/ Whether the nested arguments are named should have no bearing, since the parameter would be adjusted to a function pointer either way. If anything, the following code compiles on SoloLearn: https://code.sololearn.com/c17A226a10A2/?ref=app If I am wrong please correct me.
10th Mar 2021, 8:49 PM
Shadow
Shadow - avatar
+ 2
Well,you can use function pointers if you are trying to pass a function as an argument to a function in C/C++...?? That's all I understood by your problem...
11th Mar 2021, 4:30 PM
000
000 - avatar
+ 1
Ok, I will give you the whole code and then you see what can be done.
10th Mar 2021, 8:36 PM
TeaserCode
0
Sorry I haven't come so far. I still have not using template and foo, so I don't know these items yet. Please take one step bsck.
10th Mar 2021, 9:04 PM
TeaserCode
0
What I don't know here is how to use a reference sign & in main function when I am calling a function.
10th Mar 2021, 9:07 PM
TeaserCode
0
I hope I will soon make it corect. But first I more study.
12th Mar 2021, 7:30 PM
TeaserCode