Multidimensional Arrays

Discussion in 'C++' started by Victor Bazarov, Dec 13, 2003.

  1. Take a look at the FAQ. Section 16, question 16.15.
     
    Victor Bazarov, Dec 13, 2003
    #1
    1. Advertisements

  2. No. But my GNU C++ compiler
    g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)

    will create variable-size arrays:
    #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;
    }
    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]'
    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?
     
    E. Robert Tisdale, Dec 13, 2003
    #2
    1. Advertisements

  3. Victor Bazarov

    Jon Bell Guest

    Jon Bell, Dec 13, 2003
    #3
  4. Victor Bazarov

    Jack Klein Guest

    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
     
    Jack Klein, Dec 13, 2003
    #4
  5. Victor Bazarov

    Ron Natalie Guest

    Nope
     
    Ron Natalie, Dec 13, 2003
    #5
  6. Victor Bazarov

    Maximus Guest

    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,
     
    Maximus, Dec 13, 2003
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.