Come si implementa correttamente l'overload dell'operatore []?
Sembra che al mio compilatore piaccia decisamente la mia implementazione del lvalue, perchè l'altra non la prende mai in considerazione. Dove sbaglio?
codice:
// Overloading dell'operatore [] (rvalue)
template <typename T>
T CLASSE<T>::operator[]( const unsigned pos ) const throw(...)
{
if( pos >= size )
throw std::out_of_range( "Out Of Range exception occurs" );
return pointer[ pos ];
}
// Overloading dell'operatore [] (lvalue)
template <typename T>
T & CLASSE<T>::operator[]( const unsigned pos ) throw(...)
{
if( pos >= capacity )
throw std::out_of_range( "Out Of Range exception occurs" );
return pointer[ pos ];
}
Usati come:
codice:
// lvalue
oggetto[ i ] = value;
//rvalue
value = oggetto[ i ];
Grazie