Re: need help in dynamic memory alloction of multi-dimensional array
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Sun, 7 May 2006 21:22:52 -0400
"Allen Maki" <allen_class@xxxxxxxxxxx> wrote in message
news:OHAzSzjcGHA.2068@xxxxxxxxxxxxxxxxxxxx
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
const int max = 5;
const int max2 = 4;
class Array
{
public:
long (*pprime)[max2];
Here max2 is a constant, with the value of 4.
Array(int max, int max2)
{
pprime = new long[max][max2];
Here max2 referes to a parameter passed to the constructor, not to the
constant as in the first case. You are attempting to allocate an array
of objects of type long[max2], but it's only a valid type when max2 is a
constant, which here it isn't.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- need help in dynamic memory alloction of multi-dimensional array
- From: Allen Maki
- need help in dynamic memory alloction of multi-dimensional array
- Prev by Date: need help in dynamic memory alloction of multi-dimensional array
- Next by Date: Re: Quick question about streams...?
- Previous by thread: need help in dynamic memory alloction of multi-dimensional array
- Next by thread: Re: need help in dynamic memory alloction of multi-dimensional array
- Index(es):