Possible Duplicate:
Function argument type followed by *&
I am looking at someone else’s code right now and saw an unusual (atleast for me) function declaration syntax. Is the following valid C++ syntax?
bool Foo::Bar(Frame *&ptoframe, int msToBlock)
{
....
}
I think the developer is trying to declare a pointer to a reference.
thanks for the help
Yes, it’s valid. Read the syntax from right to left: it’s read reference to a pointer. This is important if you wish to change the pointer being passed to the function. The pointer is effectively passed by reference just like any other parameter.
Here’s a pretty example:
The value of any pointer passed to
change_ptrwill be changed because we are passing it by reference.Note, however that the value of the object to which a pointer points can still be changed through the
no_changefunction (i.e*ptr = new int). This syntax is applying only to the actual pointer, not its pointed-to object.