473,387 Members | 1,892 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,387 software developers and data experts.

Multidimensional Arrays

Hi,
I'd like to know if it's possible to allocate a multidimensional array
during runtime using the new operator. I tried but VC tells me this:

C:\Program Files\Microsoft Visual Studio\MyProjects\asdf\asdf.cpp(9) : error
C2440: '=' : cannot convert from 'int (*)[32]' to 'int *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

don't have a clue what all this mean, execpt that what I'm trying to do is
wrong =)

codes:
#include "stdafx.h"

int main(int argc, char* argv[])
{
int *test;
test = new int[32][32];

printf("Hello World!\n");
return 0;
}

TIA,Max,
Jul 22 '05 #1
5 3339
"Maximus" <ik*********@videotron.ca> wrote...
I'd like to know if it's possible to allocate a multidimensional array
during runtime using the new operator.[...]


Take a look at the FAQ. Section 16, question 16.15.
Jul 22 '05 #2
In article <b1*********************@weber.videotron.net>,
Maximus <ik*********@videotron.ca> wrote:
Hi,
I'd like to know if it's possible to allocate a multidimensional array
during runtime using the new operator.


<http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.15>

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 22 '05 #3
Maximus wrote:
I'd like to know if it's possible
to allocate a multidimensional array at run-time
using the new operator.
No. But my GNU C++ compiler
g++ --version g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)

will create variable-size arrays:
cat main.cc #include <iostream>

int main(int argc, char* argv[]) {
const int m = atoi(argv[1]);
const int n = atoi(argv[2]);
int test[m][n];
std::cout << "Hello World!" << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cc main.cc: In function `int main(int, char**)':
main.cc:6: warning: ISO C++ forbids variable-size array `test'
main.cc:6: warning: ISO C++ forbids variable-size array `test'
main.cc:6: warning: unused variable `int test[m][n]' ./main 3 4

Hello World!

Variable-size arrays were recently
introduced into the ANSI/ISO C 99 standard.
Are they part of the ANSI/ISO C++ 2003 standard?

Jul 22 '05 #4
On Fri, 12 Dec 2003 18:02:19 -0800, "E. Robert Tisdale"
<E.**************@jpl.nasa.gov> wrote in comp.lang.c++:
Maximus wrote:
I'd like to know if it's possible
to allocate a multidimensional array at run-time
using the new operator.


No. But my GNU C++ compiler
> g++ --version

g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)

will create variable-size arrays:

> cat main.cc
#include <iostream>

int main(int argc, char* argv[]) {
const int m = atoi(argv[1]);
const int n = atoi(argv[2]);
int test[m][n];
std::cout << "Hello World!" << std::endl;
return 0;
}
> g++ -Wall -ansi -pedantic -o main main.cc

main.cc: In function `int main(int, char**)':
main.cc:6: warning: ISO C++ forbids variable-size array `test'
main.cc:6: warning: ISO C++ forbids variable-size array `test'
main.cc:6: warning: unused variable `int test[m][n]'
> ./main 3 4

Hello World!

Variable-size arrays were recently
introduced into the ANSI/ISO C 99 standard.
Are they part of the ANSI/ISO C++ 2003 standard?


No.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 22 '05 #5

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:3F**************@jpl.nasa.gov...
Are they part of the ANSI/ISO C++ 2003 standard?


Nope
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
2
by: Terry | last post by:
Hi, can someone plz tell me how multidimensional arrays (like a 2-D array) are stored in memory? Are they like single dimensional arrays? Stored sequentially in one "row", so to say? Thanks ...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
3
by: Claire | last post by:
I have a multidimensional array defined as private double myArray = new double; The first column of the array contains X values, the other contains Y values I have a charting function defined as...
3
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to use jagged and multi-dimensional arrays in C++. In C# these work fine // for jagged arrays string jaggedArray = new string ; //for multidimensional arrays string...
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
2
by: oopsatwork | last post by:
Ok...so, I have been outside of the C world for a _very_ long time...but not so long as to remember how to do multidimensional arrays. So, let me state that I know how to malloc pointers to...
12
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.