Prev: Where are novel C++ findings published?
Next: conversion from `std::_List_iterator<int>' to non-scalar type `std::_List_iterator<int*>' requested
From: AnonMail2005 on 29 Jun 2010 16:54 On Jun 29, 4:27 pm, Jag <jag...(a)gmail.com> wrote: > I don't understand. Can some one explain the issue here. Thanks > ------------ > template <typename T> > static typename list<int>::iterator find_an_element(list<T>& a, const > T& b) { > typename list<T>::iterator itt = a.begin() ; > while (itt != a.end()) { > if (*itt == b) { > break ; > } > itt++ ; > > } > return itt ; > } Your function return type in list<int>::iterator instead if list<T>::iterator. HTH -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: red floyd on 29 Jun 2010 16:58
On Jun 29, 1:27 pm, Jag <jag...(a)gmail.com> wrote: > I don't understand. Can some one explain the issue here. Thanks > ------------ > template <typename T> > static typename list<int>::iterator find_an_element(list<T>& a, const > T& b) { > typename list<T>::iterator itt = a.begin() ; > while (itt != a.end()) { > if (*itt == b) { > break ; > } > itt++ ; > > } > return itt ; > } > Your function is explicitly returning list<int>::iterator. However itt is a a list<T>::iterator, and T may not be int. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |