【问题标题】:using Kinect, error C2668: ambiguous call to overloaded function使用 Kinect,错误 C2668:对重载函数的模糊调用
【发布时间】:2017-12-22 15:08:51
【问题描述】:

我刚开始使用 Visual Studio,我尝试通过 Visual Studio 运行 kinect 示例。到目前为止,ColorBasic、DepthBasic-D2D、Depth-D3D 等所有示例都运行良好,但是当我尝试运行 FaceTrackingVisualization 时出现错误:

1>d:\programme\dropbox\dropbox\uni\uni\pa_eyetracking\visualstudio\programms\samples\facetrackingvisualization\singleface\kinectsensor.cpp(435): **Error C2668: "abs": ambiguous call to overloaded function**

1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stdlib.h(363): note: kann "__int64 abs(const __int64) throw()" sein

1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stdlib.h(358): note: oder "long abs(const long) throw()"

1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stdlib.h(288): note: oder "int abs(int)"

有人知道如何解决这个错误吗?我只是使用示例代码,我不明白为什么会出现问题。 我正在使用 Visual Studio 2017 和 SDK v1.8.0。

谢谢。

【问题讨论】:

  • 请提供minimal reproducible example。我们不知道这样的“示例代码”是什么。
  • show 提供给函数的参数。
  • 发生错误的原因是“对 [an] 重载函数的模糊调用”。如果您向我们展示具有“abs”调用的示例代码部分,那么我们可以诊断问题。
  • 只是写在这里让一些敏感的人无法投票,将abs替换为fabsf以解决歧义
  • abs 替换为std::abs

标签: c++ visual-studio sdk kinect


【解决方案1】:

当编译器必须从一个没有显式参数匹配的类型进行类型转换并且有多个函数需要隐式类型转换时,就会发生这种情况。在这种情况下,有 int 和 long 和 long long 的函数,但传入的类型可能是无符号或浮点数或双精度数。

您可以将行从 std::abs(myValue) 更改为 std::abs(static_cast(myValue)),或根据输入类型强制转换为 int 或 long。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    相关资源
    最近更新 更多