السلام عليكم
هذه كود يعتمد على دالة صديقة >>operator
عندما اكتب هذا الكود ;cout<<t1 يظهر لي خطاء
عندما استخدمت Template ظهرت المشكلة؟؟
فارجو التصحيح في الكود التالي
حيث انا متاكد انة صحيح ولكن تظهرلي مشكلة ولا اعلم اية السبب
#include "stdafx.h"
#include<iostream>
using namespace std;
template <class T>
class Test{
T info;
friend ostream& operator <<(ostream &,const Test<T>&);
public:
Test(){}
~Test(){}
void set_info(T);
T get_info()const;
};
template<class T>
void Test<T>:: set_info(T set)
{
info=set;
}
template<class T>
T Test<T>:: get_info()const
{
return info;
}
template<class T>
ostream & operator << (ostream & out , const Test <T>& q)
{
out<<q.info<<endl;
return out;
}
int _tmain(int argc, _TCHAR* argv[])
{
Test<int> t1;
t1.set_info(20);
cout<<t1;
return 0;
}