By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,411 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,411 IT Pros & Developers. It's quick & easy.

func new

P: n/a
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 - [th********@wp.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?"
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Tue, 29 Jul 2003 12:13:34 +0200, "Dabroz" <th********@wp.pl> wrote:
can i allocate memory in multidimensional arrays by new?
Yes.

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.

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.