![]() |
std::vector<T>::iterator not recognised?
I'm attempting to use std::find() to located a specific element in a std::vector, and for some reason, When I try to create a std::vector<T>::iterator, g++ complains.
Does anyone know my problem? :
#include <vector>ERRORS :
basket.cpp: In member function ‘void Basket<T, capacity>::remove_item(const T&)’: |
Compiles fine in VC++ 2005, but not Dev-C++ (with g++.exe). It works OK if you typename it thought.
:
typename std::vector<T>::iterator iter = |
>std::vector<T>::iterator pos;
vector<T>::iterator is a type that depends on a template argument (T being that argument). In such a case you have to specify that you're referring to a type rather than a "thing" by using the typename keyword: :
typename std::vector<T>::iterator pos; |
Thanks Narue and Cache. :)
There is so much more to C++ then I once thought. I know the basics, but some template and class features are incredibly complicated :eek:. |
>some template and class features are incredibly complicated
I think that templates are the most complicated feature of C++. It's basically a turing complete sub-language. There's a lot of power, but only if you can wrap your brain around it. :) |
Quote:
|
>On a side not, is it standards compliant to compile without the typename?
No, in strict mode, a compliant compiler should produce a diagnostic message. |
Quote:
A compliant compiler should produce a diagnostic. A compiler that is non-compliant may not. Some compilers, by default, are a bit relaxed about standard compliance (i.e. the "strict mode", as you describe it, is disabled by default). |
| All times are GMT -5. The time now is 8:01 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC