I am trying to get the intersection of an array and a vector. I decided to make them both vectors because it's how cplusplus.com gives an example.
This is the error message I get:
and here is my code:
the getNumbers()
function returns an array.
EDIT
Here is the getNumbers()
function - it just returns a property of the same return type:
This assertion usually means that the iterators supplied as the beginning and the end of a range reference different collections.
Unless
getNumbers()
returns an array by reference, and also returns the reference to the same array, this initialization is invalid:In order for the above to work,
getNumbers()
must repeatedly return a reference to the same array. YourgetNumbers
returns a copy, because it returns an array by value.To fix this line, first call
getNumbers()
, store the result in a temporary variabletempNumbers
, like thisAlternatively, you could change your
getNumbers()
function to return aconst
reference, like this: