Функция шаблона друга приводит к ошибке неопределенных символовC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Функция шаблона друга приводит к ошибке неопределенных символов

Сообщение Anonymous »

Контекст:
В программе предполагается наличие шаблона для единого связанного списка, в котором можно найти информацию по ключу. Я хотел реализовать функцию разделения, которая бы принимала одну исходную последовательность, начинала разбивать ее с «начального» индекса, затем отправляла количество элементов «шаг 1» в результат 1, затем количество элементов «шаг 2» в результат 2 и так далее, пока не в исходном коде заканчиваются элементы для выполнения следующего шага, тогда остальные элементы в исходном коде просто передаются в текущую последовательность.
Я не понимаю, почему я получаю эту ошибку:

Код: Выделить всё

ld: Undefined symbols:
split(Sequence const&, int, Sequence&, int, int, Sequence&, int, int), referenced from:
_main in main-123c17.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Для этого кода:

Код: Выделить всё

#include 
#include 
#include 
using namespace std;

template 
// a template for a single linked list in which you may find an element's info with a key (keys are not unique)(will implement find later)
class Sequence {
private:
struct Node {
Key key;
Info info;
Node* next;
Node(Key k, Info i) : key(k), info(i), next(nullptr) {}
};
Node* head;
int length;

public:
Sequence() : head(nullptr), length(0) {}

void push(Key k, Info i) {
// adds a node to the end of the sequence
Node* newNode = new Node(k, i);
if ( !head) {
head = newNode;
} else {
Node* temp = head;
while (temp->next) {
temp = temp->next;
}
temp->next = newNode;
}
length++;
}

//copy constructor
Sequence(const Sequence& other) : head(nullptr), length(0) {
Node* current = other.head;
while (current) {
push(current->key, current->info);
current = current->next;
}
}

//destructor
~Sequence() {
while (head) {
Node* temp = head;
head = head->next;
delete temp;
}
}

//printing all info from a sequence
void print(){
Node* current = head;
while (current) {
cout next;
}
cout next;
index++;
}

bool toResult1 = true;
while (current &&(length1 > 0 || length2 > 0)){
int steps = toResult1 ? step1 : step2;
int& currentLength = toResult1 ? length1 : length2;
int movingLength;

Sequence& targetSequence = toResult1 ? result1 : result2;
int targetLength = toResult1 ? length1 : length2;

for (int i = 0; i < steps && current && currentLength > 0; i++) {
targetSequence.push(current->key, current->info);
current = current->next;
currentLength--;
targetLength++;
}
if (targetLength + steps info);
current = current->next;
currentLength--;
}
}
}
}

int main(){

Sequence source;
Sequence result1;
Sequence  result2;

source.push('A', 1);
source.push('B', 2);
source.push('C', 3);
source.push('D', 4);
source.push('E', 5);
source.push('F', 6);
source.push('G', 7);
source.push('H', 8);

cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/79173978/friend-template-function-results-in-undefined-symbols-bug-error[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»