accumulate() usage

A

Allerdyce.John

Hi,

I have a function with add elements of a STL list from 'start' to
'end'.
In the debugger, the size of the list is 2 and start is 0 and end is 1.
But it never goes itside 'do_add' and it just return 0. I expect it
just 'sum' the FIRST element (since start is 0 and end is 1).

Can you please tell me why is that?

_myList is a type of vector<int>
float getTotal(int start,int end) {
vector<int>::iterator beginItr = _myList.begin() + start;
vector<int>::iterator endItr = _myList.begin() + end;


return accumulate (beginItr, endItr, 0.0, do_add<int, float>());

}
 
N

Neelesh Bodas

But it never goes itside 'do_add' and it just return 0. I expect it
just 'sum' the FIRST element (since start is 0 and end is 1).

Can you please tell me why is that?

_myList is a type of vector<int>
float getTotal(int start,int end) {
vector<int>::iterator beginItr = _myList.begin() + start;
vector<int>::iterator endItr = _myList.begin() + end;
return accumulate (beginItr, endItr, 0.0, do_add<int, float>());

This code works fine when I tried it (After adding necessary minimal
definitions and other stuff). Could you please give the complete code
which demonstrates the problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top