I have a problem with assigning 'a' in with the following code:
int *a;
list<int> new_list;
new_list.push_back(5);
a=new_list.front();
can anyone tell me how can i store the first element from the list in my variable a?
I have a problem with assigning 'a' in with the following code:
int *a;
list<int> new_list;
new_list.push_back(5);
a=new_list.front();
can anyone tell me how can i store the first element from the list in my variable a?
That is because new_list.front() returns the first element in the list, not a pointer. new_list.front() is equivalent to *(new_list.begin()). You should check out the STL to make sure you understand what STL functions return before you use them. Here is a great link:
http://www.sgi.com/tech/stl/table_of_contents.html
the line should be *a = new_list.front(), or you can get rid of the pointer variable, or you could use an iterator, would would probably much more useful, although i do not know what you intended to do with this variable.