C++中 变量y0y1等变量 的冲突问题

之前在使用# include <bits.stdc++.h> 定义y1变量时出现下列错误信息

error: previous declaration of ‘double y1(double)’

自动弹出 了 math.h库中的源码解释
CRTIMP double __cdecl j0 (double);
_CRTIMP double __cdecl j1 (double);
_CRTIMP double __cdecl jn (int, double);
_CRTIMP double __cdecl y0 (double);
_CRTIMP double __cdecl y1 (double);
_CRTIMP double __cdecl yn (int, double);

_CRTIMP double __cdecl chgsign (double);

所以问题出在 math.h 库中

我们能看到 以上变量被征用 ,所以在使用math.h定义时 不能使用上面变量

大佬给出的 解释

Function: double j0 (double x)
j0 returns the Bessel function of the first kind of order 0 of x. It may signal underflow if x is too large.

Function: double j1 (double x)
j1 returns the Bessel function of the first kind of order 1 of x. It may signal underflow if x is too large.

Function: double jn (int n, double x)
jn returns the Bessel function of the first kind of order n of x. It may signal underflow if x is too large.

Function: double y0 (double x)
y0 returns the Bessel function of the second kind of order 0 of x. It may signal underflow if x is too large. If x is negative, y0 signals a domain error; if it is zero, y0 signals overflow and returns -∞.

Function: double y1 (double x)y1 returns the Bessel function of the second kind of order 1 of x. It may signal underflow if x is too large. If x is negative, y1 signals a domain error; if it is zero, y1 signals overflow and returns -∞.

Function: double yn (int n, double x)yn returns the Bessel function of the second kind of order n of x. It may signal underflow if x is too large. If x is negative, yn signals a domain error; if it is zero, yn signals overflow and returns -∞.

来自 知乎 @ sin1080 的回答

自己翻译吧,哈哈哈哈哈哈

Bessel Functions: _j0, _j1, _jn, _y0, _y1, _yn 多看msdn

Bessel function - Wikipedia然后可以在这里找到具体的内容

来自知乎 @ vczh 的回答

如果你需要在 C++ 利用全局变量进行前方交汇求坐标,可以按照以下步骤操作: 1. 定义全局变量 在头文件或源文件的全局作用域定义存储交点坐标的全局变量,例如: ```cpp double intersectionX; double intersectionY; ``` 2. 编写交点计算函数 编写一个函数,该函数计算前方交汇点的坐标并将结果存储在全局变量。函数的输入参数可以是两条直线的起点和终点坐标等信息。 ```cpp void calculateIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { double a1 = y2 - y1; double b1 = x1 - x2; double c1 = a1 * x1 + b1 * y1; double a2 = y4 - y3; double b2 = x3 - x4; double c2 = a2 * x3 + b2 * y3; double determinant = a1 * b2 - a2 * b1; if (determinant == 0) { // 两条直线平行,没有交点 intersectionX = NAN; intersectionY = NAN; } else { // 计算交点坐标 double x = (b2*c1 - b1*c2) / determinant; double y = (a1*c2 - a2*c1) / determinant; intersectionX = x; intersectionY = y; } } ``` 3. 在程序调用函数 在你的程序,调用 `calculateIntersection` 函数并传入需要计算交点的两条直线的坐标等信息。交点坐标将存储在全局变量,可以在程序的其他地方使用。 ```cpp int main() { // 计算两条直线的前方交汇点 double x1 = 1.0, y1 = 1.0, x2 = 2.0, y2 = 2.0; double x3 = 3.0, y3 = 1.0, x4 = 4.0, y4 = 2.0; calculateIntersection(x1, y1, x2, y2, x3, y3, x4, y4); // 输出交点坐标 cout << "Intersection: (" << intersectionX << ", " << intersectionY << ")" << endl; return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值