Question: Need help getting past an error in C++! I have all my code pasted down below. My issue is that I'm trying to call the

Need help getting past an error in C++!

I have all my code pasted down below. My issue is that I'm trying to call the functions I have in main, but they don't do anything as they are now. I'm almost positive I need to call them with parenthesis, but putting them in always results with an error saying "A nonstatic member reference must be relative to a specific object."

Below will be the source file, then the header file I made all the functions in. Thanks in advance, y'all are the best!

(Source.ccp)

#include "Header.h"

int main() { NoteList noteList; noteList.loadData("input.txt");

bool finish = false; int choice; while (finish != true) { cout << " ** Menu ** " << "1. LIST NOTES BY DATE " << "2. LIST NOTES BY COMPOSER " << "3. DELETE MOST RECENT NOTE " << "4. EXIT " << endl; cin >> choice; if (choice == 1) { &NoteList::listNotesByDate(); } else if (choice == 2) { &NoteList::listNotesByComposer; } else if (choice == 3) { &NoteList::deleteFrontNote; } else if (choice == 4) { cout << " Operations ended"; finish = true; } else { cout << " Input not recognized. Please choose a number between 1 and 4." << endl; } } return 0; }

(Header.h)

#pragma once #include #include #include

using namespace std;

class Date { private: int month, day, year; public: Date() : month(0), day(0), year(0) {} void setDate(string strDate) { month = stoi(strDate.substr(0, 2)); day = stoi(strDate.substr(3, 2)); year = stoi(strDate.substr(6, 4)); } string showDate() { return to_string(month) + "-" + to_string(day) + "-" + to_string(year); } int calculateDays() { return year * 365 + month * 31 + day; } };

class Note { private: string composer; Date date; string subject; string body; public: Note(string c, string d, string s, string b) : composer(c), subject(s), body(b) { date.setDate(d); } string getComposer() { return composer; } Date getDate() { return date; } string getSubject() { return subject; } string getBody() { return body; } };

struct noteNode { Note note; noteNode* next; };

class NoteList { private: noteNode* head; public: NoteList() : head(nullptr) {} void loadData(const char* filename) { ifstream file(filename); if (file.is_open()) { string line; string composer, date, subject, body; while (getline(file, line)) { if (line == "##########") { Note note = Note(composer, date, subject, body); addNote(note); composer.clear(); date.clear(); subject.clear(); body.clear(); } else if (line.substr(0, 10) == "COMPOSER: ") { composer = line.substr(10); } else if (line.substr(0, 6) == "DATE: ") { date = line.substr(6); } else if (line.substr(0, 9) == "SUBJECT: ") { subject = line.substr(9); } else { body += line + " "; } } file.close(); } else { cerr << "Unable to open file " << filename << endl; } } void addNote(Note note) { noteNode* newNode = new noteNode{note, head}; newNode->note = note; newNode->next = head; head = newNode; } void listNotesByDate() { cout << "Working"; noteNode* curr = head; while (curr != NULL) { if (curr->note.getBody() != "") { cout << curr->note.getComposer() << " " << curr->note.getSubject() << " " << curr->note.getDate().showDate() << endl; } curr = curr->next; } } void listNotesByComposer(string composerName) { noteNode* curr = head; while (curr != NULL) { if (curr->note.getBody() != "") { string composerInput; cout << "Enter the composer: "; cin >> composerInput; if (curr->note.getComposer() == composerInput) { cout << curr->note.getComposer() << " " << curr->note.getSubject() << " " << curr->note.getDate().showDate() << endl; } else { } } curr = curr->next; } } void deleteFrontNote() { noteNode* curr = head; noteNode* prev = NULL; if (head == NULL) { return; } else { prev = curr; curr = curr->next; head = curr; delete prev; } cout << " The latest note has been deleted."; } };

(And here's what's in the input.txt file, just in case you need it for whatever reason :P)

COMPOSER: yson DATE: 01-21-2021 SUBJECT: Picking up BODY: Reminder: Pick up vegetables for dinner after work. ########## COMPOSER: hskim DATE: 01-22-2019 SUBJECT: Dr. Appointment BODY: Dental office appointment at 3:00, tomorrow. ########## COMPOSER: yson DATE: 11-20-2021 SUBJECT: Team meeting BODY: Team meeting will be held on March 11, 2022, from 1:30 - 3:30 p.m. In the process of hiring a new worker. ##########

I'm sure there are other errors scattered in the code somewhere, but until I fix the problem I'm having now, I can't test the program and see for myself what's wrong. If you catch another issue, don't be afraid to mention it! All I'm asking for right now though is to get this forsaken main function to work properly.

Thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!