Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the (*) syntax in C++ mean?

Tags:

c++

syntax

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

like image 218
lissachen Avatar asked Nov 29 '16 15:11

lissachen


People also ask

What is the * symbol in C?

Asterisk (*) − It is used to create a pointer variable.

What * means in C language?

"*" 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.

What do you mean by & and * in C?

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.

What does ~= mean in C?

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.


2 Answers

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 ints".

like image 120
molbdnilo Avatar answered Oct 26 '22 16:10

molbdnilo


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 *).

like image 30
Jan Groothuijse Avatar answered Oct 26 '22 18:10

Jan Groothuijse