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
Asterisk (*) − It is used to create a pointer variable.
"*" can be used three ways. It can be used to declare a pointer variable, declare a pointer type, or to dereference a pointer, but it only means one level of indirection. C and C++ count the number of stars to determine the levels of indirection that are happening, or are expected to happen.
The & is a unary operator in C which returns the memory address of the passed operand. This is also known as address of operator. <> The * is a unary operator which returns the value of object pointed by a pointer variable. It is known as value of operator.
The ~ operator in C++ (and other C-like languages like C and Java) performs a bitwise NOT operation - all the 1 bits in the operand are set to 0 and all the 0 bits in the operand are set to 1. In other words, it creates the complement of the original number.
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".
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 *)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With