简体   繁体   中英

Transform C++11

I have a code that calculate the sum of a certain number of points, multiplied by the total of the questions asked, divided per 20. The thing is that the sum of a certain number of points is in vector type, and the number of the questions total is a double. So I need to convert vector in double. I got this code

return std::accumulate(begin(chiffre), end(chiffre), 0.0, [](double a, double b)->double { return a + b * 20;}) / nbtotal;

But this is C++11 and I program not using C++11, so I need to convert this code into C++98. And I really don't know how to proceed. If someone can help, don't hesitate ! And sorry for my english !! :)

You can just create a normal function:

static double myAdd(double a, double b) {
    return a + b * 20;
} 

//...
return std::accumulate(chiffre.begin(), chiffre.end(), 0.0, myAdd) / nbtotal;

You also have to change begin(chiffre) to chiffre.begin() and the same for end , because these global functions appeared only in C++11 (given that you didn't write them yourself).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM