Cannot allocate array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • saneman

    Cannot allocate array

    I get the following error when I try to allocate the below code:

    cannot allocate an array of constant size 0

    int main() {
    int dim = 3;
    int b[dim][dim];

    return 0;
    }


    What am I doing wrong?


  • Ian Collins

    #2
    Re: Cannot allocate array

    saneman wrote:
    I get the following error when I try to allocate the below code:
    >
    cannot allocate an array of constant size 0
    >
    int main() {
    int dim = 3;
    int b[dim][dim];
    >
    return 0;
    }
    >
    >
    What am I doing wrong?
    >
    Not using a C99 compiler.

    To be legal c++, you should uee a const:

    const size_t dim = 3;

    --
    Ian Collins.

    Comment

    • Juha Nieminen

      #3
      Re: Cannot allocate array

      Ian Collins wrote:
      saneman wrote:
      >I get the following error when I try to allocate the below code:
      >>
      >cannot allocate an array of constant size 0
      >>
      >int main() {
      > int dim = 3;
      > int b[dim][dim];
      >>
      >return 0;
      >}
      >>
      >>
      >What am I doing wrong?
      >>
      Not using a C99 compiler.
      >
      To be legal c++, you should uee a const:
      >
      const size_t dim = 3;
      const int dim = 3; would be fine too.

      Comment

      Working...