For example
#include <functional>
template <typename InputIterator, typename T>
inline const T accumulate( Input Iterator first, InputIterator last, const T
&val )
{
T result = val;
for ( ; first != last; ++first )
{
result = result + *first;
}
return ( result );
}
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> vi;
...
int sum = accumulate( vi.begin(), vi.end(), 0 ); // <== here is the
error
...
return 0;
}
Vladimir Grigoriev
See ADL (nickname "Koenig lookup") - namespace 'std' is added to the
lookup areas because of the arguments (which are of types declared in
'std'). At least that's how I understand it. If you want to limit the
lookup to global namespace only, qualify your name:
int sum = ::accumulate( ...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Yes. In your case, std::accumulate is found by argument-dependent loopkup (ADL, aka Koenig lookup), and ::accumulate by a normal lookup. This renders the use of unqualified name ambiguous.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
I should make a remark that I included an incorrect header file. Should be
<numeric> instead of <functional>.:) . However another question arises: How
does the compiler know that there is such name as std::accumulate if I did
not include the header <numeric>?
Vladimir Grigoriev
"Victor Bazarov" <v.Aba...@comAcast.net> wrote in message
news:hdubja$e73$1...@news.datemas.de...
Vladimir Grigoriev
"Vladimir Grigoriev" <vlad....@mail.ru> wrote in message
news:%23oBrDT5...@TK2MSFTNGP04.phx.gbl...