[Cs3] comparing objects pointed to
Mikhail Nesterenko
mikhail at cs.kent.edu
Fri Mar 19 13:52:55 EDT 2021
CS3 students,
This is regarding code fragment:
return accumulate(inFactories.begin()+1, inFactories.end(), *inFactories.begin(),
[](CarFactory *a, CarFactory *b) {
return a->getNumCarsInProduction() < b->getNumCarsInProduction() ? a: b;
}
);
In
http://antares.cs.kent.edu/~mikhail/classes/cs3/Examples/AbstractFactory/CarFactory/CarTest.cpp
That we talked about in class. accumulate() is examining the array of
pointers to objects inFactories[] and returning a pointer that points
to the object with the smallest number of cars in production (least
busy).
There was a suggestion to use std::min() instead for
comparison. However, it is a bit tricky since we need to get pointers
to objets rather than objects themselves. If you guys have an idea as
to how to simplify the code, I'd be happy to listen.
Thanks,
--
Mikhail
More information about the cs3
mailing list