当我尝试将变量分配给该迭代器时,我收到错误:expected a ";"
,其中vec
是thrust::device_vector<my_type>
,j
是int
},my_type
是模板类型:
for (thrust::device_vector<my_type>::iterator i = vec.begin(); i < vec.end(); i += j) Foo(i);
这是循环向量的正确方法吗?我是否将i
声明为正确类型?
答案 0 :(得分:1)
标准容器使用迭代器遍历其他对象(即其元素)的集合,因为迭代器是在所有标准容器中实现的抽象概念,您可以通过以下方式实现迭代器:
typename thrust::device_vector<my_type>::iterator it = vec.begin();
for (it; it != vec.end(); it = it+j)
Foo(*it);
以下是对STL容器的引用:http://www.cplusplus.com/reference/stl/