Nel tutorial di oggi imparerete come creare una funzione che copia un’array in un’altro con il controllo dei limiti. Esso funziona con tutti i tipi.
Copiate il seguente codice nell’header del file chiamandolo ArrayCopy.h

 
 
#ifndef ARRAYCOPY_H
#define ARRAYCOPY_H
 
#include
 
template
void CopyArray( type *tA, type *tB, int aSize, int bSize) // destination, source, size of destination, size of source
{
if(aSize == bSize)
{
for (int iii = 0; iii < bSize; ++iii)
{
tA[iii]= tB[iii];
}
 
}
else if(aSize > bSize)
{
int difference = aSize-bSize;
int position = aSize-difference;
for (int iii = 0; iii < bSize; ++iii)
{
tA[iii]= tB[iii];
}
for (position; position < aSize; ++position)
{
tA[position] = 0;
}
}
else if(bSize > aSize)
{
for (int iii = 0; iii < aSize; ++iii)
{
tA[iii]= tB[iii];
}
}
else
{
cerr