1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to creat two dimension array in the heap

Discussion in 'C' started by falcon eyes, May 25, 2007.

  1. falcon eyes

    falcon eyes New Member

    Joined:
    Apr 8, 2007
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Hi All
    I'm using MS-VStudio 2005and want to creat two dimension array in the heap(free store )
    but when i write the code
    float *pFloat;
    pFloat=new float[3][5];

    and compile the profram i got the following error

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


    so could someone please tell me what's wrong in my code
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
  3. falcon eyes

    falcon eyes New Member

    Joined:
    Apr 8, 2007
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Thanks and sorry
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Code:
        float (*pFloat)[5] = new float [3][5];
    
     
  5. falcon eyes

    falcon eyes New Member

    Joined:
    Apr 8, 2007
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Thanks
    i will try it and if i have any notes i will post it
     
  6. falcon eyes

    falcon eyes New Member

    Joined:
    Apr 8, 2007
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Please DaWei
    when i tryed the code u suggested
    float (*pFloat)[5] = new float [3][5];
    in my code i got this error
    error C2040: 'pFloat' : 'float (*)[5]' differs in levels of indirection from 'float *'
    So what's wrong do u have any suggestions
     
  7. tailhook123

    tailhook123 New Member

    Joined:
    May 23, 2007
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
  8. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Works for me. Perhaps you have defined it otherwise, elsewhere.
     

Share This Page