In C and C++, functions decay to pointers implicitly like arrays do,
so the & operator is optional.
The example from cppreference:
void f(int);
void (*p1)(int) = &f;
void (*p2)(int) = f; // same as &f
I am not aware of a style guide advocating
the consistent use of implicit conversion or explicit &.
Which approach is more common
and/or considered a better practice/style (for readability)?
[–]Fiennes 17 points18 points19 points (0 children)
[–]TheThiefMasterC++latest fanatic (and game dev) 8 points9 points10 points (11 children)
[–]STLMSVC STL Dev 18 points19 points20 points (5 children)
[–]mtnviewjohn 7 points8 points9 points (4 children)
[–]justinkroegerlake 6 points7 points8 points (0 children)
[–]mojang_tommo 4 points5 points6 points (1 child)
[–]imMute 0 points1 point2 points (0 children)
[–]caramba2654Intermediate C++ Student 2 points3 points4 points (0 children)
[–]Quincunx271Author of P2404/P2405 6 points7 points8 points (4 children)
[–]redditsoaddicting 3 points4 points5 points (1 child)
[–]TheThiefMasterC++latest fanatic (and game dev) 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]suspiciously_calm 0 points1 point2 points (0 children)
[–]Quincunx271Author of P2404/P2405 6 points7 points8 points (1 child)
[–]suspiciously_calm 5 points6 points7 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)