问题
int a = max_element(highesthuman[0], highesthuman[2]);
if( win > loss)
{
cout << "You won " << (win-loss) << " games more than the computer did! You used " << a << " the most.";
}
}
The above array is given by
int humanrock = 0;
int humanpaper = 0;
int humanscissors = 0;
int highesthuman [3] = {humanrock, humanpaper, humanscissors};
When running my whole program I get an error saying "invalid type argument of unary". I looked this up but was not able to understand "pointers" or what people were referring too.
回答1:
std::max_element() accepts two iterators as parameters, and returns an iterator. In your case iterators are pointers. So you should change
int a = max_element(highesthuman[0], highesthuman[2]);
to
int a = *max_element(highesthuman, highesthuman + 3);
来源:https://stackoverflow.com/questions/25964349/error-when-attempting-to-use-max-element-to-figure-out-the-highest-number-in-an