LNK2019 при реализации std::list
Мне необходимо частично реализовать контейнер "list", но вылетает LNK2019. Использую шаблон класса, но при этом без шаблона все работает.
lab8.cpp
#include "List.h"
#include <iostream>
int main() {
List<int> lst;
lst.push_back(2);
lst.push_back(5);
lst.push_back(1);
lst.push_back(131);
for (size_t i = 0; i < lst.size(); i++) {
std::cout << lst[i] << std::endl;
}
return 0;
}
List.h
#pragma once
#include "Product.h"
template<typename T>
class List {
private:
template<typename T>
struct Node {
T Data;
Node* Next;
Node(T data, Node* next = nullptr) {
Data = data;
Next = next;
}
};
size_t _size = 0;
Node<T>* Head;
public:
List();
~List();
int size();
void push_back(T data);
T& operator[](const int index);
};
List.cpp
#include "List.h"
#include <iostream>
template<typename T>
List<T>::List(): Head(nullptr) {}
template<typename T>
List<T>::~List() {}
template<typename T>
int List<T>::size() {
return _size;
}
template<typename T>
void List<T>::push_back(T data) {
Node<T>* current = this->Head;
if (current == nullptr) {
Head = new Node<T>(data);
}
else {
while (current->Next != nullptr) {
current = current->Next;
}
current->Next = new Node<T>(data);
}
_size++;
}
template<typename T>
T& List<T>::operator[](const int index) {
Node<T>* current = this->Head;
int counter = 0;
while (current != nullptr) {
if (counter == index) {
return current->Data;
}
current = current->Next;
counter++;
}
}
Product.h
#pragma once
#include <string>
struct Product {
std::string name = "";
std::string country = "";
std::string maker = "";
std::string vendorCode = "";
int price = 0;
};
Пробовал создать другой проект, но это не помогло :(
Убирал шаблон, без него работает, но хочется понять почему с ним не компилится
