Sign in to follow this  
nlbs

templated function not working

Recommended Posts

nlbs    100
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
phresnel    953
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?

Share this post


Link to post
Share on other sites
visitor    643
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
SiCrane    11839
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
nlbs    100
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