[英]C++ error: 'iterator is not a type'
這是我的代碼:
template <typename container_type>
void transfer(container_type container, iterator begin, iterator end) {
for (; begin != end; begin++)
if (!element_in_container(container, *begin))
container.insert(iterator, *begin);
}
我收到錯誤'iterator is not a type'
。
我嘗試在iterator
之前添加std::
或container_type::
沒有幫助。 我嘗試將模板定義為template <typename container_type<typename T> >
,並將迭代器定義為container_type<T>::iterator
,沒有運氣。 怎么了?
我想你是說以下
template <typename container_type>
void transfer( container_type container, typename container_type::iterator begin,
typename container_type::iterator end) {
考慮到在任何情況下您的函數都是錯誤的,因為在容器中插入元素后,迭代器可能無效。
我嘗試在迭代器之前添加
std::
或container_type::
沒有幫助。
container_type::iterator
是一個從屬名稱,因此您需要先使用typename
關鍵字將其視為類型( typename container_type::iterator
)。 這在這里有深入的解釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.