Sign in to follow this  
Mizipzor

[solved] list.front() returns const

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this