I have a member function which takes a constant reference parameter to another object. I want to const_cast this parameter in order to easily use it inside the member function. For this purpose, which of the following codes is better?:
void AClass::AMember(const BClass & _BObject)
{
// FORM #1 - Cast as an object:
BClass BObject = const_cast<BClass &>(_BObject);
// ...
}
void AClass::AMember(const BClass & _BObject)
{
// FORM #2 - Cast as a reference:
BClass & BObject = const_cast<BClass &>(_BObject);
// ...
}
Can you please compare these two forms? Which one is better in criteria of speed and memory usage?