c++ - no matching function for call to... error with template class -


i have generic double linked list, , made in vc++ 2010, , worked well, have compile gcc, can't compile it. when call method has iterator parameter, got error:

no matching function call 'dllist<int>::erase(dllist<int>::iterator, dllist<int>::iterator)'|  [...]note: candidates are: void dllist<t>::erase(dllist<t>::iterator&, dllist<t>::iterator&) [with t = int]| 

the dllist in .h file, , every method defined inline. iterator class in dllist class.

template<typename t> class dllist{ [...] public:  [...]     void erase(iterator &_first, iterator &_last){...}     iterator first(){...}     iterator last(){...} [...]     class iterator{...} [...] }; 

and code causes error:

ilist.erase(ilist.first(), ilist.last()); 

(ilist: dllist< int> ilist)

how can fix it?

void erase(iterator const &_first, iterator const &_last){...} 

this allows temporary iterators, returned first() , last(), passed. cannot non-const reference temporary.

alternatively, use function signature , work on iterator copies (if e.g. need modify them within erase):

void erase(iterator _first, iterator _last){...} 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -