带有指针作为参数问题的 C++ 函数
c++ function with pointers as argument problem
我在 c++ 中使用 fftw 进行傅里叶变换。有标准数据类型fftw_complex,它基本上是双精度[2]。我想做一个fftw_complex数组。我这样做
typedef fftw_complex fftw_complex_16[65536];
我将数组中的所有内容都设置为零。然后我有另一个函数应该检查fftw_complex_16是否为空。
bool is_empty_fftw_complex_16(fftw_complex_16 *thecomplex){
std::cout<<"Testn"<<::vowels["a:"][0][0]<<std::endl;
for (unsigned long i=0; i<65536; i++){
if(thecomplex[i][0] != 0 || thecomplex[i][1] != 0){
std::cout<<"Huch!"<<i<<std::endl;
std::cout<<thecomplex[i][0]<<" -- "<<thecomplex[i][1]<<std::endl;
std::cout<<*thecomplex[i][0]<<" -- "<<*thecomplex[i][1]<<std::endl;
return 1;
}
}
return 0;
}
忘记couts,它们仅用于调试。函数唯一应该做的是,如果指针参数指向的数组为空,则返回 true,否则返回 false。它不起作用。该函数表示数组不为空!请帮忙,我做错了什么?
问题似乎是这个
bool is_empty_fftw_complex_16(fftw_complex_16 *thecomplex){
从你的描述来看,这真的应该是这个
bool is_empty_fftw_complex_16(fftw_complex *thecomplex){
但是很难完全确定,因为您没有发布设置此数组并调用此函数的代码,不幸的是,这是错过的关键事情。
像这样的东西将是调用函数的正确方法
fftw_complex_16 array;
...
is_empty_fftw_complex_16(array);
我猜你把上面的错误声明和这个不正确的调用结合起来了。
fftw_complex_16 array;
...
is_empty_fftw_complex_16(&array);
这会编译但不执行您想要的操作。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 使用mongocxx驱动程序时包含头文件问题