pointer / array question

This is a discussion on pointer / array question within the C++ Programming forums, part of the General Programming Boards category; I need to make a dynamically-allocated two-dimensional array. so what i did was: int **arrayPtr; then i get my width ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    7

    pointer / array question

    I need to make a dynamically-allocated two-dimensional array.

    so what i did was:

    int **arrayPtr;

    then i get my width and my height.
    then:

    arrayPtr = new int[width][height];

    i keep getting this error saying:

    error C2440: '=' : cannot convert from 'int (*)[1]' to 'int ** '
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


    am I not doing this properly for a two demensional array?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >am I not doing this properly for a two demensional array?
    No.
    Code:
    int **matrix;
    
    matrix = new int*[rows];
    for ( int i = 0; i < rows; i++ )
      matrix[i] = new int[cols];
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    7
    ooh, alright I understand now

    works perfectly, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer of array of class
    By 11moshiko11 in forum C++ Programming
    Replies: 5
    Last Post: 04-05-2008, 09:58 AM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. array pointer question
    By Hoser83 in forum C Programming
    Replies: 5
    Last Post: 02-03-2006, 10:19 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  5. A question between Array and Pointer
    By Unregistered in forum C++ Programming
    Replies: 16
    Last Post: 08-05-2002, 09:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21