Reputation: 41
Im working on a c++ project for my data structures class, using nested linked lists.
I am supposed to write a program that reads student names from a file, and creates a linked list out of them. Each entry in the linked list should have the student's name, a pointer to the next student, and a pointer to a linked list of grades for that student. This program allows teachers to input grades for each student.
As for now, Im worried about finding the right way to get started.
The book provided a diagram which shows an example of how the data structure should be: diagram
struct Grade{
float score;
};
struct GradeNode{
Grade grade_ptr; //points to Grade above
GradeNode *next_gnode; //points to next Grade NODE
};
struct StudentNode {
string name; //holds Student name
GradeNode *grades; //points to linked list of grades for this student
StudentNode *next_snode; //points to next student
};
StudentNode* head = nullptr; //head of student linked list (set to nullptr)
I believe how I have this layed out makes sense but when I run code below:
void appendNode(string n){
StudentNode *node; //new node
node = new StudentNode;
node->name = n;
node->next_snode = nullptr;
//i just want to print out this node to see if value is initialized correctly
cout<<node->name<<endl; //this student's name prints out
};
It returns an error saying "linker command failed". I feel like im initializing the node wrong but dont know how to fix it.
If someone has tips on how to find a solution, or a different approach for this task using linked lists, i would really appreciate it.
Upvotes: 0
Views: 243
Reputation: 330
The error occurs when a function has been used in main without providing the function definition. Define the function before usage.
Upvotes: 0
Reputation: 30489
From image it appears you have declared and used a function buildList(std::string)
(in main
) but never provide a definition to this function.
Solution: Give a body to buildList
function.
Upvotes: 2