mercredi 24 mai 2017

Undefined symbols for architecture x86_64 (using clang) [duplicate]

This question already has an answer here:

I was trying to make a list with genericity, and when I try to compile this is what it says:

Undefined symbols for architecture x86_64:
  "List<int>::List(int)", referenced from:
      _main in main.cc.o
  "List<int>::~List()", referenced from:
      _main in main.cc.o

This is what I have typed in my .cc and .h

node.h

#ifndef __NODOS_LISTA_DOBLE__
#define __NODOS_LISTA_DOBLE__
#include <vector>
template<class T>
class Node{
private:
    Node<T>* back;
    Node<T>* next;
    T key;
public:
    Node (T key);
    virtual ~Node();
};
#endif

node.cc

#include "node.h"
template <class T>
Node<T>::Node(T key){
    this->head=nullptr;
    this->heap=nullptr;
    this->key=key;
}
template <class T>
Node<T>::~Node(){}

list.h

#ifndef __LISTA_DOBLEMENTE_ENLAZADA__
#define __LISTA_DOBLEMENTE_ENLAZADA__
#include "node.h"
#include <vector>
template<class T>
class List {
private:
    Node<T>* head;
    Node<T>* heap;
protected:
public:
    List (T key);
    List (std::vector<T>& v);
    virtual ~List();
    void MakeListNull();
};
#endif

list.cc

#include "list.h"
template <class T>
List<T>::List (T key){
    head=new Node<T>(key);
    head->back=nullptr;
    heap=head;
    heap->next=nullptr;
}
template <class T>
List<T>::List (std::vector<T>& v){
    if(v.size()>0){
        head=new Node<T>(v[0]);
        head->back=nullptr;
        Node<T>* nx=head;
        for (int cont=1;cont<v.size()-1;cont++){
            nx->next=new Node<T>(v[cont]);
            nx->next->back=nx;
            nx=nx->next;
        }
        heap=new Node<T>(v[v.size()-1]);
        heap->next=nullptr;
    }
}

template <class T>
List<T>::~List(){
    this->MakeListNull();
}

template <class T>
void List<T>::MakeListNull(){

}

main.cc

#include <iostream>
#include "list.h"

int main (int argc, char** argv){
    List<int> miLista(5);
    return 0;
}

I have been looking all the evening on internet and don't know why that error keeps popping, if anyone could help me I would be so grateful.

Aucun commentaire:

Enregistrer un commentaire