+ 1
what to prefer : function pointer Or Function from functional
Hi Any advantage of function over function pointer used in below code? https://code.sololearn.com/cA15A19A14a1
2 ответов
+ 2
In this perticular case it doesn't make any big of a difference apart from the fact that by using function pointers, you are reducing some lines of code from your program.
The real use of function pointer comes when you are creating a callback mechanism and/or need to pass address of a function to another.
That being said, function pointers are very C thing and I would recommend you to have a look functors(classes that overload "()" operator) in C++ which you can still use similar to function pointers but being a full fledged class they are comparatively faster, safer and more flexible than function pointers.
+ 1
Hi Arsenic , thank you so much...yeah functor are better compared to function pointer .
I am more interested to know on comparison between function pointer with std::function from functional header.