I need to implement a linked list and I have trouble finding an error in my code. I know that unsolved external symbol
means that I probably have a function declaration and no implementation, but I looked through my code and I can't see what's missing.
The error that I get is LNK2019: unresolved external symbol "public: __thiscall ListElement::ListElement(int)" (??0ListElement@@QAE@H@Z) referenced in function "public: __thiscall List::List(void)" (??0List@@QAE@XZ)
List.h
#ifndef LIST_H
#define LIST_H
#include "ListElement.h"
class List {
public:
ListElement *head; // wskaźnik na pierwszy element;
ListElement first = NULL; // pierwszy element
int total = 0;
List();
int get(int i);
void addFirstElement(int x);
void addLastElement(int x);
void addRandomElement(int x);
void removeFirstElement();
void removeLastElement();
void removeRandomElement();
private:
};
#endif
List.cpp
#include "stdafx.h"
#include "List.h"
List::List(){
head = &first;
}
int List::get(int i){ return -1; }
void List::addFirstElement(int x){
ListElement newEl = ListElement(x);
newEl.next = &first;
head = &newEl;
total++;
}
void List::addLastElement(int x){
ListElement* p = first.next;
while (p != NULL){
p = p->next;
}
ListElement newEl(x);
p = &newEl;
}
void List::addRandomElement(int x){
int pos = rand() % total;
//TODO
}
void List::removeFirstElement(){
}
void List::removeLastElement(){
ListElement last = get(total - 1);
delete &last;
total--;
last = get(total - 1);
last.next = NULL;
}
void List::removeRandomElement(){
}
ListElement.h
#ifndef LIST_ELELENT_H
#define LIST_ELEMENT_H
class ListElement{
public:
ListElement(int x);
int data; // wartość
ListElement * next; // wskaźnik następnego elementu
private:
};
#endif
ListElement.cpp
#include "ListElement.h"
ListElement::ListElement(int x){
data = x;
}
I realize this is probably a duplicate question, but none of the answers I found helped me solve this.