我在这里创建了一个Employees的链表类:
Node.cpp
#include "EmpNode.h"
EmpNode::EmpNode(int id, string name){
emp.id = id;
emp.name = name;
next = NULL;
}
List.cpp
#include "List.h"
#include "Header.h"
bool ListOfEmp::insertEmp(int id, string name){
EmpNode *newNode = new EmpNode(id, name);
if (!newNode){
return false; // Failure
}
else{
newNode->next = head;
head = newNode;
return true; // Success
}
}
bool ListOfEmp::findEmp(int id, const Employee &emp) const{
EmpNode *currentNode = head;
while (currentNode != 0){
if (currentNode->emp.id == id){
emp = currentNode->emp;
return true;
}
currentNode = currentNode->next;
}
return false;
}
Node.h
#pragma once
// My Node
class EmpNode {
friend class ListOfEmp;
public:
EmpNode(int id, string name);
private:
Employee emp;
EmpNode *next;
};
List.h
#pragma once
// My List of Nodes
class ListOfEmp {
public:
ListOfEmp();
~ListOfEmp();
bool findEmp(int id, const Employee &emp) const;
bool insertEmp(int id, string name);
private:
EmpNode *head;
};
错误1错误C2248:'员工:: id' :无法访问在课堂上声明的私人会员'员工' \\ 22 1 LinkedList
答案 0 :(得分:0)
我认为您希望使用其构造函数初始化emp
成员,并且您要查找的是
EmpNode::EmpNode(int id, string name)
: emp(id, name),
next(NULL)
{
}