首页 > 解决方案 > 获取 C2760 语法错误:意外标记“int”,std::max 的预期“表达式”(...)

问题描述

我正在尝试使用 C 导出构建一个 DLL,以便从 C# 中使用MathGeoLib库。

到目前为止我写的代码:

#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>

但是当我编译时,即使我定义了以下错误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.
}

问题:

我该如何解决这个错误?

标签: c++

解决方案


该行#include <algorithm>是使用 所必需的std::max


推荐阅读