为什么即使在定义之后仍存在"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
似乎不应该调用任何错误。
我仍然是一个初学者,所以如果这是微不足道的事情,请原谅我。
我知道这应该不是问题,但我为类和声明本身使用了不同的窗口。
我正在使用Visual Studio 2010运行代码。
1(在这里:
N::~N{}
您忘记了析构函数~N()
的括号:
N::~N(){};
2(在这里:
void aFr(N* n){
在这里:
void aEn(N* n){
您忘记使用范围解析运算符将函数表示为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;
}
}
这些更改后,这编译得很好。
您忘记了方法 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;
}
}
相关文章:
- Why is UINT32_MAX + 1 = 0?
- C++错误:"error: int aaa::bbb is protected within this context"
- 创建具有 new in 函数和"this is nullptr"异常的对象
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- Is !NaN not a NaN?
- Directx 11 - CompileFromFile() is not compiling
- Centos7 g++ "to_string is not in a member of std"
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- Where is std::hardware_destructive_interference_size?
- 为什么即使在定义之后仍存在"Identifier is undefined error "?
- 如何解决"identifier 'gets'/'clrscr' is undefined"问题?
- 字符串返回功能不起作用 - 'identifier is underfined'
- 使用结构体的简单"identifier 'xxx' is undefined"
- 包括 fstream,但"ifstream not found"和"identifier is undefined"
- C++ ~ 在客户端中调用函数会给出错误:"identifier ____ is undefined"
- Unreal Engine 4.19 C++Undeclared Identifier错误,但它的代码是IS声明的
- 为什么我不能在我的程序中声明一个字符串:"string is undeclared identifier"
- 访问子类中的"protected"数据时"Identifier is undefined"错误
- 如何修复简单C++应用程序中的"identifier is undefined"错误?