У меня есть следующие файлы cpp и h-файл. Это были примеры, данные нам инструктором, но они не хотят компилироваться. Я получаю эту ошибку:Ошибка компиляции связанного списка C++
linked_list.cpp:50:6: error: prototype for ‘void LinkedList::remove(LinkedListNode*, int*)’ does not match any in class ‘LinkedList’
void LinkedList::remove(LinkedListNode *node, int *return_value) {
^
In file included from linked_list.cpp:1:0:
linked_list.h:31:7: error: candidate is: void LinkedList::remove(LinkedListNode*)
void remove(LinkedListNode *node);
^
здесь код:
#include "linked_list.h"
LinkedList::LinkedList() {
this->start = NULL;
this->end = NULL;
}
LinkedList::~LinkedList() {
LinkedListNode *current = this->start;
while (current != NULL) {
LinkedListNode *temp = current;
current = current->next;
delete temp;
}
}
void LinkedList::push(int val) {
LinkedListNode *new_node = new LinkedListNode();
new_node->value = val;
new_node->next = NULL;
new_node->prev = this->end;
if (this->end != NULL) {
this->end->next = new_node;
} else {
this->start = new_node;
}
this->end = new_node;
}
int LinkedList::peek() {
if (this->end != NULL) {
return this->end->value;
}
return -1;
}
int LinkedList::pop() {
if (this->end != NULL) {
int val = this->end->value;
remove(this->end);
return val;
}
return -1;
}
void LinkedList::remove(LinkedListNode *node, int *return_value) {
if (this->start == node) {
this->start = node->next;
} else if (node->prev != NULL) {
node->prev->next = node->next;
}
if (this->end == node) {
this->end = node->prev;
} else if (node->next != NULL) {
node->next->prev = node->prev;
}
delete node;
}
Вот заголовочный файл:
#include <cstdlib>
using namespace std;
struct LinkedListNode
{
LinkedListNode *prev;
LinkedListNode *next;
int value;
};
class LinkedList
{
public:
LinkedList();
~LinkedList();
void push(int val);
bool insert_at(int val, int idx);
int peek();
int pop();
int retrieve_at(int idx);
bool remove_at(int idx);
LinkedListNode *find(int val);
private:
LinkedListNode *start;
LinkedListNode *end;
void remove(LinkedListNode *node);
};
здесь главный файл:
#include <cstdlib>
#include <iostream>
#include "linked_list.h"
using namespace std;
int main()
{
LinkedList list;
list.push(5);
cout << list.peek() << endl;
cout << list.pop() << endl;
cout << list.pop() << endl;
return 0;
}
'void remove (LinkedListNode * node);' в вашем заголовке не соответствует 'void LinkedList :: remove (LinkedListNode * node, int * return_value) {' в вашем коде. – Amit
Какая часть сообщения об ошибке неясна? Вы объявляете 'remove' для принятия одного параметра, но вы пытаетесь реализовать его как взятие двух параметров. –
@IgorTandetnik Я не уверен, что это должен быть ответ, или мы просто должны закрыть этот вопрос для тривиальной ошибки. –