1

I have a list_sorter class which gets a T type list and makes it sorted. There is my problem: it is working in one cpp file. When I try to decompose it to header file and another cpp file, I get undefined reference to `list_sorter::list_sorter(std::__cxx11::list >)'. I've read many examples, but cannot solve this.

Could somebody help me, what am I doing wrong? What should I change? Please see my files and codes lower:

listsort.h:

#ifndef listsort
#define listsort
#include<list>

template <typename T>
class list_sorter{  
    private:
    std::list<T> adat;

    public:
    list_sorter(std::list<T> be);
    void add(std::list<T> uj);
    void print();
};
#endif

list_sorter.cpp:

#include<list>
#include"listsort.h"
template <typename T>
class list_sorter{  
    private:
    std::list<T> adat;

    public:
    list_sorter(std::list<T> be): adat(be) { adat.sort();}
    void add(std::list<T> uj){
        for(auto a:uj) adat.push_back(a);
        adat.sort();
    }
    void print(){for(auto a:adat) cout<<a<<" ";}
};

try.cpp:

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

using namespace std;

int main(){
    list<int> tombocske;

    tombocske.push_back(70);
    tombocske.push_back(7);
    tombocske.push_back(2);
    tombocske.push_back(12); 

    list_sorter<int> rendezo(tombocske); 
    rendezo.print(); cout<<endl<<endl;

    list<int> tili;
    tili.push_back(45);
    tili.push_back(1);
    tili.push_back(32);
    tili.push_back(7);

    rendezo.add(tili);
    rendezo.print();

    list<string> tali;
    tali.push_back("gyozo");
    tali.push_back("kave");
    tali.push_back("alma");
    tali.push_back("pipa");

    list_sorter<string> rendezo2(tali);

    rendezo2.print();

}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

0 Answers0