linker problem

hi, i have been bashing my head against a wall for a while trying to work out this "undefined reference to.." error.

i have two data classes:

1
2
3
4
5
6
7
8
9
10
    class Customer
    {
        //...
    }
    
    class Tour
    {
        vector<Customer *> custPtrList;
        //...
    };


i have a container class for boost::ptr_vector() called P_VContainer,the Customer class has an overloaded operator >> which accepts a filestream to populate the container list. there is a template class called TourStream which passes a and a template class called DataLoader which controls the container lists and file loading functions.

i have to use templates because i am going to develop different container classes for comparison

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    template<template<class> class T>
    class TourStream
    {
        ifstream& fin;
        T<Customer> custList;
    public:
        TourStream(ifstream &fileIn, T<Customer>& list) :
            fin(fileIn),
            custList(list)
        //...
    };
    
    template <template<class> class T>
    class DataLoader
    {
        T<Customer> custList;
        T<Tour> tourList;
        //...
    };


within the DataLoader class there is a function (with all extraneous information removed):

1
2
3
4
5
6
7
8
    void loadTours(const char* fileName)
    {
        ifstream fin(fileName, ios_base::in);
        TourStream<T> tin(fin, custList);
        Tour *temp;
        tin >> *temp;
        tourList.addElementByDesc(temp);
    }


and the >> operator is overloaded like this:

1
2
3
4
5
    template <template<class> class T>
    TourStream<T>& operator>>(TourStream<T>& ts, Tour& tour)
    {
        //...
    }


in main i invoke the whole thing by:

1
2
3
    DataLoader<P_VContainer> loader;
    loader.loadCustomers("customers.txt");
    loader.loadTours("tours.txt");


when i compile it, it compiles everything fine, but when the linker works to link everything it brings up this error:

1
2
3
    main.o: In function `DataLoader<P_VContainer>::loadTours(char const*)':
    main.cpp:(.text._ZN10DataLoaderI12P_VContainerE9loadToursEPKc[_ZN10DataLoaderI12P_VContainerE9loadToursEPKc]+0x23b): undefined reference to `TourStream<P_VContainer>& operator>><P_VContainer>(TourStream<P_VContainer>&, Tour*)'
    collect2: error: ld returned 1 exit status


any ideas what it might be? i tried to cut my code down as much as possible, but if you need to know anything about the classes themselves let me know..
closed account (o3hC5Di1)
Hi there,

Is the (template) definition of operator>> in the header file or in a .cpp file?

All the best,
NwN
Topic archived. No new replies allowed.