When I compile this code in Visual Studio 2005:
template <class T>
class CFooVector : public std::vector<CFoo<T>>
{
public:
void SetToFirst( typename std::vector<CFoo<T>>::iterator & iter );
};
template <class T>
void CFooVector<T>::SetToFirst( typename std::vector<CFoo<T>>::iterator & iter )
{
iter = begin();
}
I get these errors:
c:\home\code\scantest\stltest1\stltest1.cpp(33) : error C2244: 'CFooVector<T>::SetToFirst' : unable to match function definition to an existing declaration
c:\home\code\scantest\stltest1\stltest1.cpp(26) : see declaration of 'CFooVector<T>::SetToFirst'
definition
'void CFooVector<T>::SetToFirst(std::vector<CFoo<T>>::iterator &)'
existing declarations
'void CFooVector<T>::SetToFirst(std::_Vector_iterator<_Ty,_Alloc::rebind<_Ty>::other> &)'
If I add a typedef to the CFooVector template, I can get the code to compile and work:
template <class T>
class CFooVector : public std::vector<CFoo<T>>
{
public:
typedef typename std::vector<CFoo<T>>::iterator FooVIter;
void SetToFirst( FooVIter & iter );
};
template <class T>
void CFooVector<T>::SetToFirst( FooVIter & iter )
{
iter = begin();
}
My question is, why does the typedef work when using the bare 'typename std::vector>::iterator'
declaration did not work?