Suppose we have a templated class with an STL vector as a data member:
Compiling the above code with GCC 4.0.0 under Mac OS X (via Terminal), however, generates the following error messages:Code:#include <vector> using namespace std; template <class T> class Point { public: Point(T t); vector<T> v; }; template <class T> Point<T> :: Point(T t) { v.resize(3); for (vector<T>::iterator i = v.begin(); i < v.end(); i++) *i = t; }
PowerBook:~/Desktop Maelstrom$ g++ main.cpp
main.cpp: In constructor 'Point<T>::Point(T)':
main.cpp:16: error: expected `;' before 'i' (Shown hilighted in red)
main.cpp:16: error: 'i' was not declared in this scope
I cannot find anything blatantly wrong with the this code. My first guess is that the STL vector iterator requires a concrete allocator object, but no allocator can be created since the precise type is undefined (because it's a template).
Any ideas or solutions?