Thread: create array with "new"

  1. #1
    Registered User
    Join Date
    Mar 2004

    create array with "new"

    i can create an array that way :

    int *ptrArray = new int[5] //array with 5 elements

    but i cant create a bidimensional array this way. why? any help?

    int *ptrArray = new int[5][5] //array with 25 elements

    because the compiler generate the following error message:
    C:\programas c++\ejer8_12\arreglos2.cpp(12) : error C2440: '=' : cannot convert from 'int (*)[1]' to 'int *'

    please esxcuse my poor english

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It's just a matter of getting the type correct
    int (*ptrArray)[5] = new int[5][5];

    But this only works when all the minor dimensions are constant.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2004
    got it , thanks salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Create random array
    By Hunter_wow in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2007, 05:29 AM
  3. How to create multi-dimension string array
    By mihu in forum C Programming
    Replies: 2
    Last Post: 04-02-2006, 10:09 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM