c++有时候不能调用max函数

环境 vs2019community

头文件导入

#include <iostream>
#include <algorithm>
#include <stack>

int largestRectangleArea(vector<int>& heights) {
    stack<int> s;
    int max_s = 0;
    s.push(-1);
    for (int i = 0; i < heights.size(); ++i)
    {
        while (s.top() != -1 && heights[s.top()] >= heights[i]) {
            int h = heights[s.top()];
            s.pop();

                        //这里用max不报错
            max_s = max(max_s, h * (i - s.top() - 1));

        }
        s.push(i);
    }
    while (s.top() != -1) {
        int h = heights[s.top()];
        s.pop();

                //这个地方用max就报错
        max_s = max(max_s , h * (heights.size() - s.top() - 1));

    }
    return max_s;
}

vs上报错显示
严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E0304 没有与参数列表匹配的 重载函数 "max" 实例 Project1 E:\source\repos\Project1\main.cpp 23

可是我明明导入了头文件啊,而且第一个max用的也没问题

报错为:no matching function for call to ‘max(int&, std::vector<int>::size_type)’
原因:h * (heights.size() - s.top() - 1) 被判断为std::vector<int>::size_type类型,不能隐式转换成int类型,而max需要两个参数都是int类型,所以报错了
改成下面这样: 
        int tmp = h * (heights.size() - s.top() - 1);
        max_s = max(max_s , tmp);