In code:
int a[3][4] = {1,2,3,4,
5,6,7,8,
9,10,11,12};
template<class T, int row, int col>
void invert(T a[row][col])
{
T* columns = new T[col];
T* const free_me = columns;
for (int i = 0; i < col; ++i)
{
for (int j = 0; j < row; ++j)
{
*columns = a[j][i];
++columns;//SOMETIMES VALUE IS 0
}
}
delete[] free_me;//I'M GETTING ERROR OF HEAP ABUSE IN THIS LINE
}
int main(int argc, char* argv[])
{
invert<int,3,4>(a);
}
I've observed that while iterating, value of variable columns equals zero and I think thats the problem.
Thanks for your help.