【发布时间】:2017-06-01 00:47:43
【问题描述】:
我知道有人问过类似的问题,但我似乎找不到解决方案。我一直在使用这段代码返回一个函数,但它似乎不起作用:
#include <math.h>
// Computes the bearing in degrees from the point A(a1,a2) to
// the point B(b1,b2). Note that A and B are given in terms of
// screen coordinates
double bearing(double a1, double a2, double deg, double degy) {
a1 = 37.40733;
a2 = -121.84855;
static const double TWOPI = 6.2831853071795865;
static const double RAD2DEG = 57.2957795130823209;
// if (a1 = b1 and a2 = b2) throw an error
double theta = atan2(deg - a1, degy + a2);
if (theta < 0.0)
theta += TWOPI;
return RAD2DEG * theta;
Serial.print(bearing);
}
我不断收到此错误消息:
Arduino:1.8.1(Windows 7),板:“Arduino/Genuino Uno”
C:\Users\family\Documents\Arduino\GPStester\GPStester.ino:在函数中 '双轴承(双,双,双,双)':
GPStester:90: 错误: 调用重载 'print(double (&)(double, double, double, double))' 模棱两可
Serial.print(轴承);
注意:没有已知的参数 1 从 'double(double, double, double, double)' 到 'long unsigned int' 的转换
退出状态 1 重载 'print(double (&)(double, double, double, double))' 的调用是模棱两可的模棱两可
【问题讨论】:
-
Serial.print(bearing);似乎是无法访问的代码。 -
我没有编程 arduino 但错误消息似乎表明
Serial.print预期的参数是long unsigned int。您正在将一个指向函数的指针传递给它。 -
在注释中说“点 B(b1,b2)”,然后在参数中说“deg”和“degy”,非常令人困惑。这些参数是否是“B”点?这些名称看起来像是以度数表示角度。
-
注意:在 Arduino 上,
float和double都是 4 个字节。double不是双精度。
标签: c++ arduino double overloading arduino-ide