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

Multidimensional Arrays

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.