我已经声明了一个辅助函数给我在头文件中声明的类的方法,并且由于某种原因,当我编译源代码文件I得到一个错误告诉我,我宣布一个变量或字段为void。我不知道如何解释这一点,因为我的目标是将该功能宣布为无效。void函数导致编译器错误“变量或字段'funcName'声明为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
}
如果任何人都可以发现任何会导致编译器不会将其视为函数的东西,这将不胜感激。谢谢!
P.S.我没有把它标记为kdtree文章,因为我非常肯定解决方案不依赖于代码的这个方面。
更新:
这里是kd.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
向我们展示“k-d.h”。 – cnicutar
您需要发布足够的代码示例来演示该问题。尝试将它隔离到发生错误时的绝对最小情况--10个中有9个,这将为您解决问题,如果没有,您可以发布它,并且有人应该很快发现错误。 – Ayjay
请提供一个我们可以用来重现错误的例子,如[这里](http://sscce.org)所述。 –