Sign in to follow this  
nlbs

templated function not working

Recommended Posts

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’

Share this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
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){

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this