I am trying to overload the >> operator in my template class as a friend function.The problem occurs when I want to read an object of that class;I get the following error: undefined reference to `std::istream& operator>>(std::istream&, ContBancar&)'. I have checked this post (overloading friend operator<< for template class) and I have tried the second approach which is found in the code below.
//ContBancar.h
//included all the necessary libraries
template<class T> class ContBancar;
template<class T> istream& operator>>(istream&, ContBancar<T>&);
template<class T>
class ContBancar {
string detinator;
string dataDeschidere;
T sold;
public:
ContBancar(string det="DefaultDestinatar", string data="NoData", T sol=T(0)):detinator(det),dataDeschidere(data),sold(sol){}
friend istream& operator >> <T>(istream &, ContBancar<T> &);
};
//ContBancar.cpp
#include "ContBancar.h"
template <class T>
istream & operator>>(istream &in, ContBancar<T> &ob)
{
in>>ob.detinator;
in>>ob.sold;
in>>ob.dataDeschidere;
return in;
}