简体   繁体   中英

C++ asterisk asterisk operator

I have never seen this operation done before in any languages, since this is a symbol google makes it hard to search.

What does ** mean ?

sf::TcpSocket& client = **it;

It's dereferencing a pointer to a pointer, in order to get to the original sf:TcpSocket .

It's just two * operators in a row.

In this case, you could also write:

// Given sf::TcpSocket **it;
sf::TcpSocket *tmp = *it; // Dereference once
sf::TcpSocket& client = *tmp;

I will give a very simple quick illustration:

int **i;
Say i stores an address 0x1234
*i gives us the value say 0x5678 stored on address 0x1234.
**i gives us the desired value stored on address 0x5678.

You can continue to do that until its a valid address space. But by declaring.

          int **i;

We strictly have to deference only twice, any further attempt will be thwarted by the compiler. Thus avoid bugs. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM