我创建了一个带有2个类的头文件ll.h
。代码如下:
#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{}
你忘记了析构者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;
}
}
这些更改后编译好。
你忘了方法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;
}
}