I don't understand why the following doesn't compile:
Code:
#include <iostream>
using namespace std;
/**
* Utility function used to allocate 2-D arrays
*/
template <typename T>
T** new2DArray( const int& d1, const int& d2 )
{
T ** result = new T*[d1];
result[0] = new T[d1 * d2];
for (int row=1; row < d1; row++)
{
result[row] = result[row-1] + d2;
}
return result;
}
void t1( const int* test )
{
// Can't modify array
}
void t2( const int** test )
{
// Can't modify 2D array
}
void main()
{
int* test1 = new int();
int** test2 = new2DArray<int> (3, 3);
t1( test1 ); // Compiles
t2( test2 ); // Doesn't compile
delete test1;
delete test2[0];
delete test2;
}