Skip to main content
GameDev.net gamedev.net
🔒 Locked

templated function not working

Started by nlbs Dec 17, 2008 at 10:27 AM 4 replies 700+ views
Original Post
nlbs
nlbs
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’
visitor
visitor
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 is instantiated to find that out), except with VC++.
SiCrane
SiCrane
You probably want:
inline typename QMap::const_iterator incrementIterator(const typename QMap::const_iterator& it, const typename QMap::const_iterator& endItr, int i){
plastique
plastique
My bet would be that the compiler misses a "typename" keyword in front of the "QMap::const_iterator" and is unsure what to make of it.
nlbs
nlbs
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.