It seems all my problems involve templates. Anyways, my problem is whenever and wherever I put:
Code:
std::vector<T>::iterator iter;
I get the compiler error:
error: expected ';' before 'iter'
I've tried putting the above code directly in a template method of a template class and directly as a member of the same class in it's definition. Each time I get the same error where it occures. I feel stupid because I think I'm missing something very fundamental here. Can anyone help? Thanks.
Intel Core Duo Macbook w/ Mac OS 10.5.6
gcc 4.2.1 (i386-apple-darwin9.1.0) and Xcode 3.1.1
My guess is that you need to disambiguate with typename since the nested name iterator depends on T, which is presumably the template parameter. For example:
Code:
typename std::vector<T>::iterator iter;
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Well, I don't think much of it is very relevant, but here you go:
Code:
template<class T> class SomeClass
{
public:
void someMethod (void)
{
...
std::vector<T>::iterator iter; // I get the error everywhere. Whether I put it here...
...
}
protected:
std::vector<T>::iterator iter; // .. Or here, it doesn't matter
};
Edit:
It looks like laserlight was right, because it will work now. It's just that I don't understand why I needed to do that.
Intel Core Duo Macbook w/ Mac OS 10.5.6
gcc 4.2.1 (i386-apple-darwin9.1.0) and Xcode 3.1.1
It's just that I don't understand why I needed to do that.
Because std::vector<T>::iterator can be interpreted as a non-type name (e.g., a variable name) or as a type name, and the rules say that it should be interpreted as a non-type name by default.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Because std::vector<T>::iterator can be interpreted as a non-type name (e.g., a variable name) or as a type name, and the rules say that it should be interpreted as a non-type name by default.
Bookmarks