и не понимаю в чем дело
                  
                  
                  Есть файл list.hpp (ниже его код) и list.cpp где определяются все методы для класса
                  
                  
                  #ifndef H_LIST
                  
                  
                  #define H_LIST
                  
                  
                  
                  
                  
                  #include <iostream>
                  
                  
                  
                  
                  
                  template <typename T>
                  
                  
                  class List {
                  
                  
                      struct Node {
                  
                  
                          T data;
                  
                  
                          Node* prev;
                  
                  
                          Node* next;
                  
                  
                      };
                  
                  
                      Node* begin;
                  
                  
                      Node* end;
                  
                  
                      size_t size;
                  
                  
                  public:
                  
                  
                      enum class ListErrors {
                  
                  
                          invalid_index
                  
                  
                      };
                  
                  
                      List();
                  
                  
                      List(const List<T>& list);
                  
                  
                      List& operator=(const List<T>& list);
                  
                  
                      void add(size_t idx, const T& data);
                  
                  
                      void remove(size_t idx);
                  
                  
                      T& get(size_t idx);
                  
                  
                      const T& get(size_t idx) const;
                  
                  
                      void print() const {
                  
                  
                          size_t i = 0;
                  
                  
                          Node* cur = begin;
                  
                  
                          while (cur != nullptr) {
                  
                  
                              std::cout << "index = " << i << "; data = " << cur->data << std::endl;
                  
                  
                              i++;
                  
                  
                              cur = cur->next; 
                  
                  
                          }
                  
                  
                      }
                  
                  
                      ~List();
                  
                  
                  private:
                  
                  
                      Node* get_node(size_t idx);
                  
                  
                  };
                  
                  
                  
                  
                  
                  #endif
                  
                  
                  Скомпилирован этот модуль g++ -Wall -Wextra -c list.cpp  - никаких ошибок
                  
                  
                  Затем написал main.cpp такого содержания:
                  
                  
                  #include <iostream>
                  
                  
                  #include "list.hpp"
                  
                  
                  int main() {
                  
                  
                     List<int> l;
                  
                  
                     l.add(0, 10);
                  
                  
                     return 0;
                  
                  
                  }
                  
                  
                  Скомпилировал так: g++ -Wall -Wextra main.cpp list.o -o main
                  
                  
                  И тут получаю ошибку линкера
                  
                  
                  /usr/bin/ld: /tmp/cc9z1Utr.o: in function `main':
                  
                  
                  main.cpp:(.text+0x24): undefined reference to `List<int>::List()'
                  
                  
                  /usr/bin/ld: main.cpp:(.text+0x40): undefined reference to `List<int>::add(unsigned long, int const&)'
                  
                  
                  /usr/bin/ld: main.cpp:(.text+0x51): undefined reference to `List<int>::~List()'
                  
                  
                  /usr/bin/ld: main.cpp:(.text+0x77): undefined reference to `List<int>::~List()'
                  
                  
                  collect2: error: ld returned 1 exit status
                  
                  
                  Не подскажете почему неопределенные ссылки на это все, если они были определены в list.cpp?
                  
                  
                
так у тебя шаблонный класс
Обсуждают сегодня