If you can see the correct values in the
copyToReturn
array inside the function, but they disappear when you try to access them in another function, then I would
guess that you are writing the values outside of the memory allocated in line 3. If it is outside of the allocated memory then it may be overwritten at any time. You have both
results
and
copyToReturn
the same size, but
results
is copied into
copyToReturn
at an offset (
copyToReturn + endCopying
). If
mySize
is just the right size for
results
, then
copyToReturn
must be at least
mySize + endCopying
in size, or you will be writing beyond the end of the array.
Are you giving the proper arguments to the copy function?
http://www.cplusplus.com/reference/algorithm/copy/
Copies the elements in the range [first,last) into a range beginning at result.
Returns an iterator to the last element in the destination range.
The behavior of this function template is equivalent to:
1 2 3 4 5 6
|
template<class InputIterator, class OutputIterator>
OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result )
{
while (first!=last) *result++ = *first++;
return result;
}
|