times' undeclared (first use this function)

L

learning_C++

Hi,
I compiled some code which includs times<int>(). The compiler says
"times' undeclared (first use this function)".
I also included the header <functional> in my code.
But After I replaced "times<int>()" with "multiplies<int>()" it works.

What is wrong with my code?

Thanks,

#include <numeric>
#include <vector>
#include <functional>
#include <iostream>

using namespace std;

int main()
{

vector<int>::iterator iter;

int d1[10] = {1,2,3,4,5,6,7,8,9,10};
vector<int> v1(d1, d1+10);

int sum = accumulate(v1.begin(), v1.end(), 10);
int prod = accumulate(v1.begin(), v1.end(),
1, times<int>());
cout << "For the series: ";
for(iter = v1.begin(); iter != v1.end(); iter++)
cout << *iter << " ";
cout << " where N = 10." << endl;
cout << "The sum = (N*N + N)/2 = " << sum << endl;
cout << "The product = N! = " << prod << endl;
return 0;
}
 
P

Phillip Mills

But After I replaced "times<int>()" with "multiplies<int>()" it works.

What is telling you that 'times' should work? On my system, I can see
'multiplies' defined in <stl_function.h>, which is included by
<functional>, but there's nothing called 'times' that I can detect.
 

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
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top