So I was doing a linked list assignment where given two numbers in a linked list form, add the numbers up and make the final answer in a linked list form. I keep getting an "undeclared identifier" error for my code and I was wondering how to fix it.
Error message:
List.cpp:48:3: error: use of undeclared identifier 'append' append(h, c);
Thanks.
#include <iostream>
#ifndef LISTNODE_H
#define LISTNODE_H
using namespace std;
class ListNode {
public:
ListNode();
ListNode(int value, ListNode* next);
int value;
ListNode *next;
private:
friend class List;
};
#endif
#include <iostream>
#include "ListNode.h"
using namespace std;
ListNode:: ListNode() {
value = 'b';
next = NULL;
}
#include <iostream>
#include "ListNode.h"
#include <vector>
#ifndef LIST_H
#define LIST_H
using namespace std;
class List {
public:
List();
void append(ListNode* node, vector<char> c);
ListNode *head;
};
#endif
#include <iostream>
#include <string>
#include "List.h"
#include <vector>
#include "ListNode.h"
using namespace std;
void List:: append(ListNode *node, vector<char> c) {
//ListNode *temp
for(int i = 0; i < c.size(); i++) {
if(head == NULL) {
head = node;
}
else {
ListNode* itr = head;
while(itr -> next != NULL) {
itr = itr -> next;
}
node = itr -> next;
node -> value = c[i];
cout << node -> value << endl;
}
}
}
List:: List() { //Initializes the head and the tail for the whole class
head = NULL;
}
int main() {
ListNode *h;
string num1, num2, sentence;
vector<char> c;
cout << "Type in two numbers" << endl;
cout << "Number 1: " << endl;
cin >> num1;
cout << "Number 2: " << endl;
cin >> num2;
//cout << "Type in a sentence: " << endl;
//cin >> sentence;
cout << "--------" << endl;
for(int i = 0; i < num1.size(); i++) {
c.push_back(num1[i]);
}
append(h, c);
return 0;
}