473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 - [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
1 1542
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

90
by: Mark Hahn | last post by:
"Michael Geary" <Mike@Geary.com> wrote ... >Does anyone have some sample code where obj$func() would be used? > (Apologies if I missed it.) There have been so many messages about delegation...
3
by: Jason | last post by:
Hi, Im running windows xp pro and compiling using dev c++ 4. I have the following situation: #include <iostream> #include <string> using namespace std; int main() {
5
by: modemer | last post by:
I saw someone use the following code: void func(MyClass *& myCls) { myCls->test(); } // call func(): func(new MyClass);
6
by: ooze | last post by:
In the unix like system, there is a func ptr signal defined as below at the last line ,but I don't know how to understand it. becoz the more general to define a func ptr is the following void...
14
by: Vinko Vrsalovic | last post by:
Hello, I read a couple of posts ago that these are not equivalent, and that the former means 'no arguments specified' and that calling for instance func(3,"THREE",&myint) is legal. What's the...
6
by: nutty | last post by:
Hi all, I have the following problem ( explanation below code ): // main.cpp class noncopyable { protected: noncopyable() {}
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
28
by: Yevgen Muntyan | last post by:
Hey, Consider the following code: void func (void) { } void func2 (void) {
6
by: Alex Vinokur | last post by:
------ foo.c ------ void func() {} int main() { func (100, 200, 300); return 0; } ------------------- How can func() use its arguments 100, 200, 300?
6
by: not_a_commie | last post by:
I'm struggling here. Please help me complete this method: Type ToFuncType(Type owningType, Type result) { return typeof(Func<typeof(owningType), typeof(result)>); } Or more generally, given...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.