- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经为我在头文件中声明的类的方法声明了一个辅助函数,但出于某种原因,当我编译源代码文件时,我收到一条错误消息,告诉我我将一个变量或字段声明为 void。我不确定如何解释这一点,因为我的目标是将该函数声明为无效。
编译错误如下:
k-d.cpp:10: error: variable or field ‘insert_Helper’ declared void
k-d.cpp:10: error: ‘node’ was not declared in this scope
k-d.cpp:10: error: ‘root’ was not declared in this scope
k-d.cpp:10: error: expected primary-expression before ‘*’ token
k-d.cpp:10: error: ‘o’ was not declared in this scope
k-d.cpp:10: error: expected primary-expression before ‘int’
下面代码中的第 10 行相当于第 5 行。
源码如下:
#include <iostream>
#include "k-d.h" //Defines the node and spot structs
using namespace std;
void insert_Helper(node *root, spot *o, int disc) {
(...Some code here...)
}
void kdTree::insert(spot *o) { //kdTree is a class outlined in k-d.h
insert_Helper(root, o, 0); //root is defined in k-d.h
}
如果有人能发现任何会导致编译器不将其视为函数的内容,我们将不胜感激。谢谢!
附言我没有将此标记为 kdtree 帖子,因为我很确定解决方案不依赖于代码的那个方面。
更新:
这里是 k-d.h:
#ifndef K_D_H
#define K_D_H
// Get a definition for NULL
#include <iostream>
#include <string>
#include "p2.h"
#include "dlist.h"
class kdTree {
// OVERVIEW: contains a k-d tree of Objects
public:
// Operational methods
bool isEmpty();
// EFFECTS: returns true if tree is empy, false otherwise
void insert(spot *o);
// MODIFIES this
// EFFECTS inserts o in the tree
Dlist<spot> rangeFind(float xMax, float yMax);
spot nearNeighbor(float X, float Y, string category);
// Maintenance methods
kdTree(); // ctor
~kdTree(); // dtor
private:
// A private type
struct node {
node *left;
node *right;
spot *o;
};
node *root; // The pointer to the 1st node (NULL if none)
};
#endif
和p2.h:
#ifndef P2_H
#define P2_H
#include <iostream>
#include <string>
using namespace std;
enum {
xCoor = 0,
yCoor = 1
};
struct spot {
float key[2];
string name, category;
};
#endif
最佳答案
首先,您需要限定 kdTree::node
,因为它被声明为内部结构。其次,您必须使 insert_Helper
成为您的类的成员,因为 node
是私有(private)的。
额外提示:从 .h
文件中删除 using
指令,而是限制您对 string
等的所有使用。考虑包括许多 cpp
文件中的那个 header 。
关于c++ - 无效函数导致编译器错误 "variable or field ‘funcName’ 声明无效”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7750116/
这个问题已经有答案了: Are 'Arrow Functions' and 'Functions' equivalent / interchangeable? (5 个回答) 已关闭 5 年前。 我最
我收到 2 条警告: 函数“funcName”的隐式声明 “funcName”的先前隐式声明在这里 不知道为什么。 最佳答案 正如警告所说。函数的“隐式”声明通常是尚未定义的。您能否也包含发出该警告的
我正在制作移动球程序。当我输入“onSubmit();”时在 form 的 onsubmit 属性中,什么都没发生。但我想看看执行函数时发生的移动球。控制台中没有发生任何错误。 之后我像这样修改了我
我有一个库文件。它有一个类似包装器的 ponOS 函数替换。我想在函数 ponOS 中显示调用它的函数的名称。 $> cat ./parasha_lib.sh #!/bin/bash function
我有一个实用程序方法可以进行一些日志记录。 我想在日志中看到调用方法的名称,而不是实用方法的名称。 为了测试我尝试了这个(后来我想通过检查模块从调用者那里得到“bar”)。 def helper(..
这是我用于记录的格式化字符串: '%(asctime)s - %(levelname)-10s - %(funcName)s - %(message)s' 但是为了显示日志消息,我有一个包装器做更多的
为什么代码段 A echo "params are ${FUNCNAME[@]}; param count is ${#FUNCNAME[@]}" 返回 params are main; param
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我有很多函数,它们经常相互嵌套。为了简单的调试目的,我决定使用 bash 提供的 FUNCNAME 环境变量数组来跟踪代码流。这是示例代码: test1(){ test2;} test2(){ tes
我有一个像这样导入的函数: import { myFunc } from './myFunc.js'; 我尝试使用字符串作为函数名称来运行此函数(字符串的内容可能会更改): let fnStr = "
在 another question ,有人有一个不正确的类定义,其中包含如下代码: var myClass = function() { ... this.name() = func
当我尝试包含 js 文件时遇到烦人的错误“ Uncaught ReferenceError :funcName 未定义” 我正在使用 laravel 4.2,我使用 php View 文件来包含 js
这个问题在这里已经有了答案: What is the difference between a function expression vs declaration in JavaScript? [
POSIX shell 是否有类似于 $FUNCNAME 的东西?在 bash ? 最佳答案 No. POSIX sh 标准要求具有特殊行为的变量列表 is quite small , 并且没有给出等
有时我使用 %(funcName)s 配置 python 日志格式化程序。但当函数名称很长时我不喜欢这样。 使用 python 日志记录 %(funcName)s 时可以缩短日志记录 header 吗
不知道有没有功能!请告诉我这可能吗? 类似的东西: spy(obj, 'funcName').and.returnValue(5); // spy will return a fake data wh
我已经为我在头文件中声明的类的方法声明了一个辅助函数,但出于某种原因,当我编译源代码文件时,我收到一条错误消息,告诉我我将一个变量或字段声明为 void。我不确定如何解释这一点,因为我的目标是将该函数
我不小心在编写模板函数特化代码时犯了一个错误,结果构造通过了 VS17 的编译。 (下面包含的代码中的第三个构造) 这是一个有效的结构吗?我该如何调用这个函数? template void temp
我在头文件中找到以下代码,并且在另一个头文件中定义了“BOOT”类。 class BOOT* boot(void); 它看起来像一个函数的声明,但它以class开头。 最佳答案 这是一个详细的类型说明
我见过几个这种形式的语法示例(我在快速搜索柯里化(Currying)时看到了这个) func funcName(a: TypeOfA)(b: TypeOfB) -> returnType { r
我是一名优秀的程序员,十分优秀!