-3
我做了一個鏈表類員工在這裏我的代碼:鏈表訪問私有成員錯誤C2248
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的
錯誤消息非常明確。什麼似乎是問題? – Borgleader
你還沒有發佈'員工'的代碼,但似乎它的成員是私人的,至少是'id'成員。 –
也許你的意思是從'id'和'name'構造'Employee'? – Kevin