我想在C中使用一个只能迭代特定类型元素的迭代器.在以下示例中,我想仅迭代SubType实例的元素.
vector<Type*> the_vector; the_vector.push_back(new Type(1)); the_vector.push_back(new SubType(2)); //SubType derives from Type the_vector.push_back(new Type(3)); the_vector.push_back(new SubType(4)); vector<Type*>::iterator the_iterator; //***This line needs to change*** the_iterator = the_vector.begin(); while( the_iterator != the_vector.end() ) { SubType* item = (SubType*)*the_iterator; //only SubType(2) and SubType(4) should be in this loop. ++the_iterator; }
我如何在C中创建这个迭代器?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。