template<typename T>
void Transpose(T** Data, std::size_t Size)
{
for (int I = 0; I < Size; ++I)
{
for (int J = 0; J < I; ++J)
{
std::swap(Data[I][J], Data[J][I]);
}
}
}
int main()
{
int A[4][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
int* Ptr = &A[0][0];
int** P = &Ptr;
Transpose(P, 4); //ERROR! Access Violation.
}
Versus:
int main()
{
int** B = new int[4];
for (int I = 0, K = 1; I < 4; ++I)
{
B[I] = new int[4];
for (int J = 0; J < 4; ++J)
{
B[I][J] = K++;
}
}
Transpose(B, 4); //Works fine..
}
So how can I distinquish the difference? In other words, how can I figure out which kind of T**
they are passing?