I have a structure defined that contains a std::list. In my code, I try to iterate through this list, but I get some odd results.
struct my_struct_t {
std::list<int> my_list;
//More fields
};
This is my structure as defined in my header file.
And some sample code in a file that includes this header would be:
std::list<int>::iterator my_iterator;
struct my_struct_t* test_struct = (struct my_struct_t*) malloc(sizeof(struct my_struct_t));
my_iterator = test_struct->my_list.begin();
printf("Beginning of list address: %p\n", my_iterator);
my_iterator = test_struct->my_list.end();
printf("End of the list address: %p\n", my_iterator);
printf("Address of the list: %p\n", &(test_struct->my_list));
This code compiles and runs fine, but the output would be something like:
Beginning of list address: (nil)
End of the list address: 0x86f010
Address of the list: 0x86f010
The last two lines make perfect sense to me, since the list should be empty. But how/why am I getting a null pointer for the beginning? How can I fix this?