C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

func new

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Dabroz
Guest





PostPosted: Tue Jul 29, 2003 10:13 am    Post subject: func new Reply with quote



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





PostPosted: Thu Jul 31, 2003 10:39 pm    Post subject: Re: func new Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.