Vox wrote:Have you ever seen this?
Code: Select all
{
Something* param = new Something();
function(*param);
}
void function(Something& param)
{
}
Pointer converted to reference? Reference is a pointer.
Now, I don't see any pointer converted here
You're passing an object to function which will be passed by reference, though. Remember that
Something *param and
*param are different things. First declares a pointer, second gets the object the pointer points to (commonly called dereferencing, but this would make it even worse now
)
So indeed both pointer and reference link to the same address as Electron mentioned, but pointers are in no way references nor is it vice versa.
One important point to references is that they can't be NULL (read the C++ reference for this one), but apparently this does not help if somewhere the destructor is called.
BTW: STL also has lots of these reference pitfalls. They have a warning with most container classes that references are only valid until next reallocation, so I should have known before