8
I would like to create a function similar to Array.Copy
from C# to C++.
This function has the prototype thus:
public static void Copy(
Array sourceArray,
int sourceIndex,
Array destinationArray,
int destinationIndex,
int length
);
And I’d like to do a function that does the same function in C++.
I tried to do using a for
, but I couldn’t make it work with the destinationIndex
.
My code:
template <T> void Buffer <T> ::copy(T * src, int indexSrc, T * dst, int indexDst, int elements) {
for (int srcAux = indexSrc, dstAux = indexDst, int aux = 0; aux != elements; srcAux++, dstAux++, aux++) {
dst[indexDst] = src[srcAux];
}
}
Post what you’ve already done.
– Laerte
My function was like this:
template<T>
void Buffer<T>::copy(T *src, int indexSrc, T *dst, int indexDst, int elements){
 for(int srcAux = indexSrc, dstAux = indexDst, int aux = 0;aux != elements;srcAux++, dstAux++, aux++){
 dst[indexDst] = src[srcAux];
 }
}
– Thiago Henrique Hupner