Search code examples
c++boostcontainersptr-vector

making boost::ptr_vector container class push_back function


im just getting my head around container classes and templates, and am having trouble working out how to implement them properly.. all of my problems are pretty similar, so once i get this sorted, i think i should be okay..

here is the code for the push_back member function that i am trying to implement:

//data is of type boost::ptr_vector<T>

template <class T>
void P_VContainer<T>::push_back(T* item)
{
    data.push_back(item);
}

this is how it is defined in p_vcontainer.h:

void push_back(T* item);

this is the error im getting from the compiler:

main.cpp:(.text+0x89f): undefined reference to `P_VContainer<Customer>::push_back(Customer*)'

this is how i am implementing it in main:

P_VContainer<Customer> myvector;

Customer *a = new Customer("C004", "Testy McTestington");

myvector.push_back(a);

any ideas as to what im doing wrong?


Solution

  • Do not divide your templates to declaration and implementation. Implement them right in header files.