代码之家  ›  专栏  ›  技术社区  ›  aybe

获取C2760语法错误:意外的标记“int”,std::max的预期“expression”<int>(…)[重复]

c++
  •  0
  • aybe  · 技术社区  · 6 年前

    这个问题已经有了答案:

    我正在尝试用C导出为 MathGeoLib 从C_消耗的库。

    到目前为止我写的代码:

    #include "stdafx.h"
    #include "MathGeoLib/MathGeoLib.h"
    
    OBB* OptimalEnclosingOBB(const vec* pointArray, int numPoints)
    {
        const auto obb1 = OBB::OptimalEnclosingOBB(pointArray, numPoints);
        const auto obb2 = new OBB(obb1);
        return obb2;
    }
    

    stdafx.h文件:

    #pragma once
    #include "targetver.h"
    #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
    // Windows Header Files
    #include <windows.h>
    

    但是当我编译时,我得到 the following error 即使我定义了 NOMINMAX :

    1>c:\build\mathgeolib\include\mathgeolib\geometry\quadtree.inl(699): error C2760: syntax error: unexpected token 'int', expected 'expression'
    

    这就是Visual Studio 2017的发展方向:

    https://github.com/juj/MathGeoLib/blob/master/src/Geometry/QuadTree.inl#L699

    template<typename T>
    int QuadTree<T>::NumNodes() const
    {
        return std::max<int>(0, nodes.size() - 3); // The nodes rootNodeIndex+1, rootNodeIndex+2 and rootNodeIndex+3 are dummy unused, since the root node is not a quadrant.
    }
    

    问题:

    如何修复此错误?

    1 回复  |  直到 6 年前
        1
  •  2
  •   M.M    6 年前

    线 #include <algorithm> 必须使用 std::max .