"...redeclared as different kind of symbol" ?
"...redeclared as different kind of symbol"?
#include <stdio.h>
#include <math.h>
double integrateF(double low, double high)
{
double low = 0;
double high = 20;
double delta_x=0;
double x, ans;
double s = 1/2*exp((-x*x)/2);
for(x=low;x<=high;x++)
delta_x = x+delta_x;
ans = delta_x*s;
return ans;
}
它说低和高被"重新宣布为不同类型的符号",我不知道这意味着什么。基本上,我在这里所做的(阅读:尝试)是从低(我设置为 0)到高 (20) 进行积分以找到黎曼和。for 循环看起来也有点迷幻...我太迷茫了。
编辑:
#include <stdio.h>
#include <math.h>
double integrateF(double low, double high)
{
low = 0;
high = 20;
double delta_x=0;
double ans = 0;
double x;
double s = 1/2*exp((-x*x)/2);
for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
ans = ans+(delta_x*s);
}
return ans;
}
^这仍然不起作用,在大括号和所有之后。它说"对'WinMain@16'的未定义引用"......
你在函数内部重新定义了低和高,这与参数中定义的那些冲突。
for 循环正在做
for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
}
你是故意的吗
for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
ans = delta_x*s;
}
但是我认为您想做ans += delta_x*s;
low
和high
已经作为integrateF
方法的参数传递。但是它们在方法中再次重新声明。因此错误。
低和高已经作为 integrateF 方法的参数传递,它们在方法中再次重新声明。
并且 x 在用于计算 s. 时没有被赋值。
双X,ANS;双精度 s = 1/2*exp((-x*x)/2);
你可能想这样尝试:-
for(x=low;x<=high;x++)
{ //Use brackets since you are redefining low and high inside the function
delta_x = x+delta_x;
ans = delta_x*s;
}
或
for(x=low;x<=high;x++)
{ //Use brackets since you are redefining low and high inside the function
delta_x = x+delta_x;
}
编辑:-
它说"对'WinMain@16'的未定义引用"
确保已定义main() or WinMain()
。还要检查 main() 是否未在命名空间中定义
导致此错误的另一种方法是在代码中"重新定义"您的函数,其中该名称标签已用作主函数之外的变量 - 像这样(伪代码):
double integrateF = 0;
main(){
// get vars to integrate ...
}
double integrateF(double, double){
//do integration
}
您甚至不必调用 main 内部的函数来尝试编译时出错,相反,编译器无法理解: double integrateF = 0 = (double, double) { };
在主功能之外。
在参数中声明数据类型后,不必重新声明它们。
而不是
double integrateF(double low, double high)
{
double low = 0;
double high = 20;
.
.
.
}
你应该这样做
double integrateF(double low, double high)
{
low = 0;
high = 20;
.
.
.
}
相关文章:
- Usages of std::move
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- 使用JsonCpp将数据返回到带有pybind11的python会在python调用中产生Symbol not foun
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- Deprecation of _writeBarrier()
- constexpr begin of a std::array
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- C++ "error: invalid use of void expression"
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- CppSQLite 抛出"LNK2019: unresolved external symbol"错误
- 赛通"Cannot take address of memoryview slice"
- C++ Version Of Double.longBitsToDouble
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++错误"redefinition of 'string' as different kind of symbol"
- 为什么我会收到这个'redeclared as different kind of symbol'错误?
- "...redeclared as different kind of symbol" ?
- C++编译错误:"Double array redeclared as different kind of symbol"