J
josh
Hi I've a dubt!
when we have overloaded functions the compiler chooses the right
being based on the argument lists...but when we have two subscript
overloaded functions it resolves them being based on the const type.
Infact if I use the Array on the left side i.e like a1[2] = 111
then it uses the first while if I use cout << a1[2] it uses the
second...
why????
int &Array:perator[]( int subscript )
{
// check for subscript out of range error
assert( 0 <= subscript && subscript < size );
return ptr[ subscript ]; // reference return
}
const int &Array:perator[]( int subscript ) const
{
// check for subscript out of range error
assert( 0 <= subscript && subscript < size );
return ptr[ subscript ]; // const reference return
}
when we have overloaded functions the compiler chooses the right
being based on the argument lists...but when we have two subscript
overloaded functions it resolves them being based on the const type.
Infact if I use the Array on the left side i.e like a1[2] = 111
then it uses the first while if I use cout << a1[2] it uses the
second...
why????
int &Array:perator[]( int subscript )
{
// check for subscript out of range error
assert( 0 <= subscript && subscript < size );
return ptr[ subscript ]; // reference return
}
const int &Array:perator[]( int subscript ) const
{
// check for subscript out of range error
assert( 0 <= subscript && subscript < size );
return ptr[ subscript ]; // const reference return
}