为什么定义后还有"Identifier is undefined error "?
Why is there a "Identifier is undefined error " even after it's been defined?
我创建了一个头文件 ll.h
,里面有 2 个 类。代码是这样的:
#pragma once
#include<iostream>
#include<conio.h>
using namespace std;
class N{
public:
int data;
N *next;
public:
N(int);
~N();
};
class ll{
public:
N *head;
public:
ll();
~ll();
void aFr(N*);
void aEn(N*);
};
N::N (int d){
data = d;
next = NULL;
}
N::~N{}
ll::ll(){
head = NULL;
}
ll::~ll(){}
void aFr(N* n){
n->next = head; //identifier "head" undefined
head = n;
}
void aEn(N* n){
if (head == NULL)// identifier "head" undefined
{
head = n;
n->next = NULL;
}
}
尽管这两个函数中的 head
似乎不应调用任何错误。
我还是个初学者,如有不足请见谅。
我知道这应该不是问题,但我对 类 和声明本身使用了不同的 windows。
我正在使用 Visual Studio 2010 运行 代码。
您忘记了 class 方法 aFR 和 aEn 的方法声明 (ll:)
void ll::aFr(N* n){
n->next = head; //identifier "head" undefined
head = n;
}
void ll::aEn(N* n){
if (head == NULL)// identifier "head" undefined
{
head = n;
n->next = NULL;
}
}
1) 这里:
N::~N{}
你忘了 the parentheses 析构函数 ~N()
:
N::~N(){};
2) 这里:
void aFr(N* n){
这里:
void aEn(N* n){
您忘记 use scope resolution operator 将函数表示为 class ll
的方法
void ll::aFr(N* n){
n->next = head; //identifier "head" undefined
head = n;
}
void ll::aEn(N* n){
if (head == NULL)// identifier "head" undefined
{
head = n;
n->next = NULL;
}
}
这些更改后编译正常。
我创建了一个头文件 ll.h
,里面有 2 个 类。代码是这样的:
#pragma once
#include<iostream>
#include<conio.h>
using namespace std;
class N{
public:
int data;
N *next;
public:
N(int);
~N();
};
class ll{
public:
N *head;
public:
ll();
~ll();
void aFr(N*);
void aEn(N*);
};
N::N (int d){
data = d;
next = NULL;
}
N::~N{}
ll::ll(){
head = NULL;
}
ll::~ll(){}
void aFr(N* n){
n->next = head; //identifier "head" undefined
head = n;
}
void aEn(N* n){
if (head == NULL)// identifier "head" undefined
{
head = n;
n->next = NULL;
}
}
尽管这两个函数中的 head
似乎不应调用任何错误。
我还是个初学者,如有不足请见谅。
我知道这应该不是问题,但我对 类 和声明本身使用了不同的 windows。
我正在使用 Visual Studio 2010 运行 代码。
您忘记了 class 方法 aFR 和 aEn 的方法声明 (ll:)
void ll::aFr(N* n){
n->next = head; //identifier "head" undefined
head = n;
}
void ll::aEn(N* n){
if (head == NULL)// identifier "head" undefined
{
head = n;
n->next = NULL;
}
}
1) 这里:
N::~N{}
你忘了 the parentheses 析构函数 ~N()
:
N::~N(){};
2) 这里:
void aFr(N* n){
这里:
void aEn(N* n){
您忘记 use scope resolution operator 将函数表示为 class ll
void ll::aFr(N* n){
n->next = head; //identifier "head" undefined
head = n;
}
void ll::aEn(N* n){
if (head == NULL)// identifier "head" undefined
{
head = n;
n->next = NULL;
}
}
这些更改后编译正常。