Having trouble using vector::iterator Problem with compiling C++ code

I’m having a very specific problem using C++ vector iterators in .cu source files. I get an “undefined identifier” compiler error using iterators inside member functions of templatized classes. For instance,

template <class myType>

class Foo {


	vector<myType> a;

	Foo() : a(3,3) {}

	void increment1() {

		for (vector<myType>::iterator iter = a.begin(); iter < a.end(); iter++) *iter++;


	void increment2() {

		for (int i=0; i<a.size(); i++) a[i]++;



Class Foo contains vector a. There is a class member function to increment every element of vector a. The first version “increment1” uses a vector iterator and will NOT COMPILE, giving the “undefined identifier iter” error. The second version “increment2” does not use an iterator and it compiles and works correctly. What the heck is going on???

Can anyone duplicate this error in a .cu file and confirm it please???

Did I discover a bug in the NVCC compiler/linker?? Either that, or some setting is wrong in my MS Visual Studio environment.

(As a side note, I’ve tried a non-template version of class Foo, and both increment1 and increment2 work correctly. The problem seems specific to vector iterator inside template classes.)

for (typename vector::iterator iter = a.begin(); iter < a.end(); iter++)

Adding keyword ‘typename’ did the trick. But now I have to go back to my library source code and add in ‘typename’ to many functions.

Thanks for help. :thumbsup: