【求助】关于const_iterator与iterator转换
各位大虾好:
小弟遇到了个难题,求教各位大虾。
在Turbolinux10上编译时出现如下错误:
error: invalid use of const_cast with type `__gnu_cxx::__normal_iterator<TopicUnit*, std::vector<TopicUnit, std::allocator<TopicUnit> > >', which is not a pointer, reference, nor a pointer-to-data-member type
error: invalid const_cast from type `__gnu_cxx::__normal_iterator<const TopicUnit*, std::vector<TopicUnit, std::allocator<TopicUnit> > >' to type `__gnu_cxx::__normal_iterator<TopicUnit*, std::vector<TopicUnit, std::allocator<TopicUnit> > >'
其中出错的代码是
for ( TopicUnitList::const_iterator tu = tu_list.begin(); tu != tu_list.end(); tu++) {
ins_result = topics.insert(const_cast<TopicUnitList::iterator>(tu)->getMatchTopicTitle().topicTitle->getTopic());
if (ins_result.second) new_tu_list.push_back(*tu);
}
谢谢各位:p :eek: