Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be the purpose of using the reference and dereference operators immediately in sequence "&*B"?

Tags:

c++

I have seen this in our code a couple times and it immediately makes me suspicious. But since I don't know the original intent I am hesitant to remove it.

//requires double indirection which I won't go into
FooClass::FooFunction(void ** param)
{
  //do something
}

SomeClass * A = new SomeClass();
SomeClass **B = &A;
FooFunction( reinterpret_cast<void**>(&*B) );   // what is happening here?

The "&*B" part is the part in question? Feel free to integrate explanation of the reinterpret cast but I am pretty familiar with cast techniques.

like image 701
BuckFilledPlatypus Avatar asked Dec 07 '22 06:12

BuckFilledPlatypus


1 Answers

I've done similar things with iterators - dereference the iterator to get a reference, and then do the "&" operator to get a pointer.

I don't see why it would be doing anything here though. If the type to the right of "&*" is a pointer type it does nothing.

like image 124
Greg Rogers Avatar answered May 14 '23 09:05

Greg Rogers