1

我正在尝试使用 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 结构的定义

4

2 回答 2

8

sqrt只接受一个论点。你给它两个。也许你打算这样做:

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

还是您将 sqrt 与hypot混淆了?

于 2012-06-18T15:04:53.570 回答
2

根据Opengroup的说法,sqrt 只有一个参数

于 2012-06-18T15:05:32.350 回答