The problem is in the operator[]
function. The code idx = 0
sets idx
to 0
. So all of your calls to operator[]
will return the first element, and therefore there is no out-of-bounds error unless the array is empty.
You probably meant to write if ( idx >= 0 && idx < size )
.
BTW the throw
aborts the function, it makes no sense to return
after throw
.