xcode中架构x86_64的未定义符号
编译架构x86_64时出现未定义符号错误 我构建了一个游戏树,并使用xcode中架构x86_64的未定义符号,xcode,xcode4.2,linker-errors,Xcode,Xcode4.2,Linker Errors,编译架构x86_64时出现未定义符号错误 我构建了一个游戏树,并使用isEmpty()函数检查树中的哪些节点是空的 #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> //#include "header.h" #define YES 10 #define NO 20 struct Node { Node ** children;
isEmpty()
函数检查树中的哪些节点是空的
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include "header.h"
#define YES 10
#define NO 20
struct Node
{
Node ** children;
int childCount;
char name[1];
int empty;//YES or NO
int sequence;
double value;
};
using namespace std;
bool isEmpty(Node, int);
bool isEmpty(Node **ptr, int bsize) {
for (int i = 0; i<bsize; i++) {
for (int j = 0; j < bsize; j++) {
if((*(ptr+i)+j)->empty == YES){
return true;
}
}
}
return false;
}
int main (int argc, const char * argv[])
{
int size = 4;
Node tree[size][size];
// some stuff
if (isEmpty(tree[size][size], size)) {
cout<<"this is empty\n";
return 0;
}
return 0;
}
虽然没有显示错误,但我不确定如何将二维数组树传递到isEmpty()
函数中
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include "header.h"
#define YES 10
#define NO 20
struct Node
{
Node ** children;
int childCount;
char name[1];
int empty;//YES or NO
int sequence;
double value;
};
using namespace std;
bool isEmpty(Node, int);
bool isEmpty(Node **ptr, int bsize) {
for (int i = 0; i<bsize; i++) {
for (int j = 0; j < bsize; j++) {
if((*(ptr+i)+j)->empty == YES){
return true;
}
}
}
return false;
}
int main (int argc, const char * argv[])
{
int size = 4;
Node tree[size][size];
// some stuff
if (isEmpty(tree[size][size], size)) {
cout<<"this is empty\n";
return 0;
}
return 0;
}
#包括
#包括
#包括
#包括
//#包括“header.h”
#定义是10
#定义第20条
结构体类型
{
节点**子节点;
int儿童计数;
字符名[1];
int empty;//是或否
int序列;
双重价值;
};
使用名称空间std;
bool为空(Node,int);
bool isEmpty(节点**ptr,int bsize){
for(int i=0;i空==YES){
返回true;
}
}
}
返回false;
}
int main(int argc,const char*argv[]
{
int size=4;
节点树[大小][大小];
//一些东西
if(isEmpty(树[size][size],size)){
cout您的isEmpty
函数原型与您的isEmpty
定义不匹配
遗憾的是,C++在把多维数组传递给函数时不是很友好。你的选项是:
请删除数组和用户指针。您将不得不使用动态分配
不要使用二维数组,而是使用大小为(长*宽)
的一维数组
对阵列使用通用的固定大小
2号可能是最简单的。代码:
#define YES 10
#define NO 20
using namespace std;
#include <iostream>
struct Node
{
Node ** children;
int childCount;
char name[1];
int empty;//YES or NO
int sequence;
double value;
};
using namespace std;
bool isEmpty(Node ptr[], int bsize) {
for (int i = 0; i<bsize; i++) {
for (int j = 0; j < bsize; j++) {
if(ptr[i * bsize + j].empty == YES){
return true;
}
}
}
return false;
}
int main (int argc, const char * argv[])
{
int size = 4;
Node tree[size * size];
// some stuff
if (isEmpty(tree, size)) {
cout<<"this is empty\n";
return 0;
}
return 0;
}
#定义是10
#定义第20条
使用名称空间std;
#包括
结构体类型
{
节点**子节点;
int儿童计数;
字符名[1];
int empty;//是或否
int序列;
双重价值;
};
使用名称空间std;
bool-isEmpty(节点ptr[],int-bsize){
对于(inti=0;i在我修改它之后,发生了另一个错误:if(isEmpty(tree[size][size],size))处调用“isEmpty”没有匹配函数{此外,我会使用#define YES true
和define No false
来代替发明新的轮子。