new , strucure and PROGRAM CRASH

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babu198649
    New Member
    • Sep 2007
    • 22

    new , strucure and PROGRAM CRASH

    hi
    i have a structure xml_data


    struct xml_data
    {
    int prf;
    int *pVsipl_buffer;
    };




    i have declared and allocated memory like this in constructor

    data = new xml_data;
    data->pVsipl_buffe r = new int[LOOP*COL]//LOOP and COL are
    //#define(d) constants;
    xml_data *data;




    now i pass this strucure pointer as an argument to a function (bpg) which resides in another file

    bpg(xml_data * ptVsip_obj)
    {
    for(m=0;m<LOOP; m++)
    for(n=0;n<COL;n ++)
    {
    ptVsip_obj->pVsipl_buffe r[m*COL+n]; //if i comment this line no
    //crashing of program
    //else crash
    }
    }



    bpg(data); //crashes


    should i have to new the structure and the array in both the files.
    (i.e) in called function and calling function.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Originally posted by babu198649
    i have declared and allocated memory like this in constructor
    What constructor?? I don't see a constructor here.

    Maybe you could post the actual struct with the constructor in it plus the constructor itself.

    Comment

    • babu198649
      New Member
      • Sep 2007
      • 22

      #3
      What constructor?? I don't see a constructor here.
      i have not posted the entire program .

      thanks for reply


      i have found the error.

      while newing the class i have allocated like this

      data = new xml_data;
      data->pVsipl_buffe r = new int(LOOP*COL);


      instead of square brace( [LOOP*COL] ) i have used curly brace((LOOP*COL)) .


      but it had compiled well but caused runtime error

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        I see. So you created a new int with a value of LOOP*COL rather than an array of int with LOOP*COL elements.

        Glad you found it.

        Comment

        Working...