Data structure/Vector

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kazzie
    New Member
    • Jul 2007
    • 6

    Data structure/Vector

    I am trying to read a file and then store the results in a data structure. One of the members of the structure is a vector. I use the following to push back the data 'p' into the vector 'v1'.

    Assume structure called Rulestrc

    Rulestrc* tp = NULL;

    other coding

    tp -> v1.push_back(p) ;

    The code compiles but does not run. I know it has something to do with the vector but I am not sure what ie can you have a vector that is a member of a structure. Can you please advise
    Thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The little bit I see here shows your tp pointer as NULL. That is, it does not point to a vector. That will cause code like tp-> to crash your program.

    You also say that the vector is a member of a struct:
    [code=cpp]
    struct Data
    {
    vector<int> theData;
    };
    [/code]

    You need a Data variable and then you can use the vector member:
    [code=cpp]
    Data d;
    d.theData.push_ back(10);
    [/code]

    Comment

    • oler1s
      Recognized Expert Contributor
      • Aug 2007
      • 671

      #3
      Describe what "doesn't run" means. The information given is so vague we can't make a diagnosis. Plus, what issues did you discover in your debugging efforts?

      Comment

      Working...