+ 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

10th Feb 2021, 7:35 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Antworten
+ 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.
10th Feb 2021, 12:26 PM
Arsenic
Arsenic - avatar
+ 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.
11th Feb 2021, 2:51 PM
Ketan Lalcheta
Ketan Lalcheta - avatar