 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dabroz Guest
|
Posted: Tue Jul 29, 2003 10:13 am Post subject: func new |
|
|
can i allocate memory in multidimensional arrays by new?
for example:
int* something;
something=new int[20][20][20];
it doesn't work! how i can make that?
- dabroz - [the_dabroz (AT) wp (DOT) pl]
"The emperor is a rotting shell, holding together a long dead empire with
fetid dreams and lies. Will you listen to them or embrace Chaos?"
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Thu Jul 31, 2003 10:39 pm Post subject: Re: func new |
|
|
On Tue, 29 Jul 2003 12:13:34 +0200, "Dabroz" <the_dabroz (AT) wp (DOT) pl> wrote:
| Quote: | can i allocate memory in multidimensional arrays by new?
|
Yes.
| Quote: | for example:
int* something;
something=new int[20][20][20];
it doesn't work! how i can make that?
|
It does not compile because the type of the 'new' expression is
not
int*
but
int (*)[20][20]
Declare your pointer as
int (*something)[20][20];
and it will compile.
But better, if you absolutely must program at the lowest
level instead of using the standard library, 'typedef' like so:
int main()
{
struct Tensor
{
int elem[20][20][20];
};
Tensor* t = new Tensor;
t->elem[1][2][3] = 666;
delete t;
}
General recommendation is, however, to use standard library and
boost collection classes.
Hth.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|