c++ - Cannot cast list iterator to an object -
i error:
error c2682: cannot use 'dynamic_cast' convert 'std::_list_iterator<_mylist>' 'userbean *'
when executing:
list<userbean> * userbeans = getuserbeans(); for(list<userbean>::iterator = userbeans->begin(); != userbeans->end(); i++) userbean * newuser = dynamic_cast<userbean*>(i);
am doing wrong, or can not convert iterator items objects?
sometimes iterators implemented raw pointers container items, more times not, not pointers @ all, don't treat them way. correct way access item iterator refers dereference iterator, eg:
userbean &newuser = *i;
or:
userbean *newuser = &(*i);
iterators override ->
operator can access members of referenced item, in cases iterator refers actual object instance (which yours does) , not pointer object instance, eg:
i->somememberhere
Comments
Post a Comment