【问题标题】:No matching function for call to 'sqrt' in XCode 4.3在 XCode 4.3 中调用“sqrt”没有匹配的函数
【发布时间】:2012-06-18 15:00:45
【问题描述】:

我正在尝试使用 C++ 为 Mac 制作 SDL 游戏。我已经让所有与 SDL 相关的工作正常,但是当我尝试使用 sqrt 函数时,我收到错误 no matching function for call to 'sqrt'。这是我的包含列表和我的第一个函数(main() 函数现在并没有真正做任何事情):

#include <iostream>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <math.h>

#include "geometry.h"

using namespace std;

void drawLine(vector2 start, vector2 end)
{
    double x = end.x - start.x;
    double y = end.y - start.y;
    double length = sqrt(x*x, y*y); // I get the error here
}

我也尝试过导入,结果相同。我需要在 Mac(Lion,XCode 4.3)上做些什么才能让它工作吗?

编辑:为了完整起见,geometry.h 包含 vector2 结构的定义

【问题讨论】:

    标签: c++ macos xcode4 standard-library


    【解决方案1】:

    sqrt 只接受一个参数。你给它两个。也许您打算这样做:

    double length = sqrt(x*x + y*y);
    

    或者您是否将 sqrt 与 hypot 混淆了?

    【讨论】:

    • 谢谢 - 不敢相信我自己没有发现。我需要一些咖啡。
    【解决方案2】:

    sqrt 只有一个参数,根据Opengroup

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-16
      相关资源
      最近更新 更多