1

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;
}
  • I have also read this post but I did't find an answer for my error.I have followed the instruction in that post. – Sergiu Talmacel May 10 '19 at 13:57
  • 1
    If you followed the instructions then you moved the template definition from the .cpp into the .h. If you actually did that and the problem still exists (and you didn't just forget to compile again), edit the question accordingly or ask a new question. – nwp May 10 '19 at 14:01

0 Answers0