Birbal
Birbal

Reputation: 63

Difficulty in understanding function-pointers in c++

I am reading The C++ Programming Language by Bjarne Stroustrup. It somewhere uses using keyword to make function-pointer datatypes P1 and P2 like this:

using P1 = int(∗)(int∗);

using P2 = void(∗)(void);

But then it uses using keyword to make another function-pointer datatype:

using CFT = int(const void∗, const void∗);             -(1)

then it uses CFT to declare a function-pointer and passes it in some ssort function:

void ssort(void∗ base, siz e_t n, size_t sz, CFT cmp);

My question is if it is making a function-pointer datatype using "using" then shouldn't line-(1) be:

using CFT=int(*)(const void*, const void*); 

rather than what it actually is?

Upvotes: 3

Views: 153

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385104

In C and C++, the (*) is optional here.

Yes, this is confusing. It's an oddity regarding function pointer types.

It would have been better had the author stuck to one of the two possible syntaxen.

Upvotes: 5

Related Questions