我正在尝试为项目创建链接列表。我有这两个文件(一个.h 和一个.cpp)。我不确定如何制作一个复制构造函数,所以我不确定这是否与它有关。我想如果有人也想指出我正确的方向,那会很有帮助。谢谢你。
#include <iostream>
#include "studentList.h"
using namespace std;
// Default Constructor for StudentList
// Creates Dummy Head Node for a new empty list
StudentList::StudentList ()
{
// Create the dummy head node
Node* Head; // Creates Head Node
Head = new Node;
Head->next = NULL; // Sets pointer to NULL by default
}
//Copy Constructor
StudentList::StudentList(const StudentList& list)
{
}
void StudentList::addStudentList(Student newStudent)
{
在这里得到错误!!!!!!
if (Head->next == NULL)
{
Head->next->student = newStudent;
Head->next->prev = Head;
Head->next->next = NULL;
}
}
这是.h文件
#include <iostream>
#include "Student.h"
using namespace std;
class StudentList{
public:
//Default Constructor
StudentList();
//Copy Constructor
StudentList(const StudentList& list);
//Add Student Method
void addStudentList(Student);
private:
// Node struct to hold Student data and with pointers to a previous and next node in linked list
struct Node {
Student student;
Node* prev;
Node* next;
};
};