templated function not working

Started by
4 comments, last by nlbs 15 years, 4 months ago
template <class KeyT , class ValT>
inline QMap<KeyT, ValT>::const_iterator incrementIterator(const QMap<KeyT, ValT>::const_iterator& it, const QMap<KeyT, ValT>::const_iterator& endItr, int i){
	int itr = 0;
	while(it != endItr || itr++ <= i)++it;
	return it;
}
Why the above code doesn't compile and fires compilation error.
expected initializer before ‘incrementIterator’
Advertisement
a) Could you please post more context?
b) Could you please reformat your code, say, with 1 expression per line?
c) Could you please post the complete error-log?
Whenever you have a nested type within a template class like this:

template <class KeyT , class ValT>inline QMap<KeyT, ValT>::const_iterator ...


the typename keyword is mandatory in front of QMap to tell that what follows is a type (and not for example a static member - the compiler shouldn't need to wait until QMap<KeyT, ValT> is instantiated to find that out), except with VC++.
You probably want:
inline typename QMap<KeyT, ValT>::const_iterator incrementIterator(const typename QMap<KeyT, ValT>::const_iterator& it, const typename QMap<KeyT, ValT>::const_iterator& endItr, int i){
My bet would be that the compiler misses a "typename" keyword in front of the "QMap<KeyT, ValT>::const_iterator" and is unsure what to make of it.
I did also put typename in argument list and return type however I wrongly put it before const which did not worked now when I put it after const it worked.Thanks

This topic is closed to new replies.

Advertisement