Reputation: 229
What does the following syntax mean?
set<element*, bool (*) (element *, element *)> * getNumbers();
I'm not familiar with the (*)
part. Any explanation would be great. Thanks
Upvotes: 9
Views: 17223
Reputation: 320
It is a function pointer, more precisely bool (*) (element *, element *)
is the type of a function pointer. In this case its a function that takes two element
pointers and returns a bool
.
Its makes more sense when you see it used as function parameter, then it will have a name after the first *
. For example bool (*fun) (element *, element *)
.
Upvotes: 2
Reputation: 66371
Here it means that the second template parameter is a function pointer:
bool (*) (element *, element *)
is "pointer to a function that takes two element*
s and returns bool
".
You may also see (*)
in connection with pointers to arrays;
int (*) [32]
is the type "pointer to an array of 32 int
s".
Upvotes: 10
Reputation: 4493
Second template argument is function pointer, designed to compare 2 element*
. If you put such function pointer in constructor of std::set - you will be able to create set of elements with custom compare function (or without overloaded operator<).
Upvotes: 0
Reputation: 72271
bool (*) (element *, element *)
names the type of a pointer to function, where the function takes two element*
pointers as parameters and returns a bool
.
Upvotes: 0
Reputation: 7341
It's a function pointer. You can read about it further here, for example: http://www.cprogramming.com/tutorial/function-pointers.html
Upvotes: 0