Panowie,
Zaczynam sobie przygotowywac custom helper'a dla wielowymiarowych tablic. Zaczalem od dwoch metod template:
- inicjalizacja tablicy:
template <typename T>
T** initArr2DT(T** arr2DPtr, int iLength, int jLength)
{
arr2DPtr = new T*[iLength];
for (int i = 0; i < iLength; i++)
{
arr2DPtr[i] = new T[jLength];
memset(arr2DPtr[i], '\0', sizeof(arr2DPtr[i]));
}
return arr2DPtr;
}
- kopiowanie tablicy:
template <typename T>
T** copyArr2DT(T** arr2DPtr, T** arr2DCopyPtr, int iLength, int jLength)
{
arr2DCopyPtr = new T*[iLength];
for (int i = 0; i < iLength; i++)
{
arr2DCopyPtr[i] = new T[jLength];
for (int j = 0; j < jLength; j++)
{
arr2DCopyPtr[i][j] = arr2DPtr[i][j];
}
}
return arr2DCopyPtr;
}
Prosze o ich ocene i ewentualne wskazowki co do ulepszenia kodu.
Z gory dziekuje :)