• Advertisement
Sign in to follow this  

[solved] list.front() returns const

This topic is 4034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a list with class instances, I want to create a pointer to one of these instances.
#include <list>
 
std::list<foo> mylist;
foo *bar = &mylist.front(); // cant do this


I get this error:
error C2440: 'initializing' : cannot convert from 'const foo *__w64 ' to 'foo *'
As Ive understood it, from list documentation, it can return both a list::const_reference and a normal reference. So why does list only return const in my case? [Edited by - Mizipzor on April 6, 2007 7:13:43 AM]

Share this post


Link to post
Share on other sites
Advertisement
Post the real, actual code showing this behavior. .front() is likely returning a const reference because the list object itself is const.

Share this post


Link to post
Share on other sites
No worries, I got help from a friend to solve it. Thanks anyway. :)

Edit: Maybe I should post the solution to. The function in which I did this was decleared const, I didnt need to change anything, but this made list (understandably) only return const items.

[Edited by - Mizipzor on April 6, 2007 7:00:27 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement