我正在尝试将我的模板类中的>>运算符作为朋友函数重载。当我想读取该类的对象时出现问题;我得到以下错误:对`std的未定义引用: :istream&operator >>(std :: istream&,ContBancar&)” 。 我已经检查了这篇文章(overloading friend operator<< for template class),并尝试了下面的代码中提供的第二种方法。
//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;
}