I read many of the other questions about this linker error, but I still wasn't able to solve it yet...
vector.hpp
#ifndef vector_hpp
#define vector_hpp
namespace vec
{
template<class T> class Vector
{
private:
T* arr;
unsigned int numberOfElements;
public:
Vector();
~Vector();
void push_back(const T&);
void pop_back();
void pop_front();
unsigned int size() const;
T& at(int);
T& front();
bool empty() const;
T& operator[](const int) const;
};
}
#endif
vector.cpp (not everything, would be too long)
#include "vector.hpp"
#include <iostream>
namespace vec
{
template<class T>
Vector<T>::Vector()
: arr(nullptr), numberOfElements(0)
{
return;
}
template<class T>
Vector<T>::~Vector()
{
delete[] arr;
}
template<class T>
unsigned int Vector<T>::size() const
{
return numberOfElements;
}
...
}
patientenliste.hpp
#ifndef patientenliste_hpp
#define patientenliste_hpp
#include "vector.hpp"
#include <iostream>
#include "patient.hpp"
using namespace std;
class Patientenliste
{
private:
vec::Vector<Patient> liste;
public:
Patientenliste& operator+= (const Patient&);
vec::Vector<Patient>& getPListe();
friend ostream& operator<< (ostream&, const Patientenliste&);
};
ostream& operator<< (ostream&, const Patientenliste&);
#endif
patientenliste.cpp
#include "patientenliste.hpp"
Patientenliste& Patientenliste::operator+= (const Patient& p)
{
liste.push_back(p);
return *this;
}
vec::Vector<Patient>& Patientenliste::getPListe()
{
return liste;
}
ostream& operator<< (ostream& os, const Patientenliste& p)
{
if(p.liste.size() == 0)
os << "Keine Patienten in der Liste.";
else
for(unsigned int i=0; i < p.liste.size(); i++)
os << p.liste[i] << endl;
return os;
}
I have some more files/classes in my project but every class which uses my Vector-class I get the Linker-error:
patientenliste.cpp:(.text+0x32): Nicht definierter Verweis auf vec::Vector<Patient>::size() const'
patientenliste.cpp:(.text+0x5e): Nicht definierter Verweis auf
vec::Vector::size() const'
patientenliste.cpp:(.text+0x6c): Nicht definierter Verweis auf `vec::Vector::operator [ ] (int) const'
(in english "Nicht definierter Verweis auf" means "undefined reference to") I have absolutely no clue about what's going wrong... I already tried it wihtout the namespace vec, but that didn't work either.