I am working on homework and wanted to know what this is actually defined as:
list < NAME > * m_ofList
Where name comes from a struct like so:
typedef struct name
{
int age;
int height;
} NAME;
I want to know what it is so I know how to insert to it or access it: push_back, insert, etc.
So I understand this now, but I am stuck because of some type of memory access: it produces a segmentation fault and I have been unable to figure this out.
Where do I need to initialize my new list? it doesn’t work in constructor or in the functions. Just FYI, it is a private list so it can only be used for member functions (i.e. m_ofList). I can produce code if anyone would like to help…
Assuming
using namespace stdorusing std::list, that’s a pointer to a list of objects of the class/struct NAME. To put objects in it, first you need to initialize it:or:
Then you can put items in it:
If you went with dynamically allocating the list with
new, it needs to be properly disposed of when you are done with it:My question for you is, why is it a pointer in the first place? You could just declare it (as you should) like this:
Then you wouldn’t have to worry about disposing of it. It would be taken care of by scoping rules.