Why can't my vector access the variables in my nested structs?

Posted by chucknorris on Stack Overflow See other posts from Stack Overflow or by chucknorris
Published on 2012-12-01T05:01:03Z Indexed on 2012/12/01 5:03 UTC
Read the original article Hit count: 73

Filed under:
|
|
|
|
     #include<iostream>
     #include<vector>
     #include<string>
     #include<list>
     using namespace std;


    struct record{
    int id;
    string fName;

};

struct cells{
    list<record> rec;
};

   vector<cells> hp;


  int main()
  {
**hp.front().rec.front().fName = "jon";


return 0;

}

I have 2 structs. The first struct, struct record, is composed of 2 regular variables. In struct 2, I have a linked list of type "record", which includes all the variable listed in struct 1. Why is it that when ever I attempt to access a variable in the structs, using my vector, I get the error "linked list iterator not dereferencable?"

© Stack Overflow or respective owner

Related posts about c++

Related posts about variables