Aug 3, 2010 at 1:33pm UTC
It works. Thanks brotha.
I've got another problem. I'm getting error again, when i try to compile my program.
1 2 3 4 5 6 7 8 9 10 11
//Number.h
template <class T>
class CNumber
{
public :
CNumber(void ):m_Number(43){}
~CNumber(void );
friend std::ostream & operator << (std::ostream &, CNumber<T> &);
private :
T m_Number;
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <iostream>
#include "Number.h"
using namespace std;
template <class T>
ostream & operator << (ostream &, CNumber<T> &);
int _tmain(int argc, _TCHAR* argv[])
{
CNumber<int > number;
cout<<number<<endl;
system("pause" );
return 0;
}
template <class T>
ostream & operator << (ostream & o, CNumber<T> & num)
{
return o<<"Number=" <<num.m_Number;
}
Last edited on Aug 3, 2010 at 1:45pm UTC
Aug 3, 2010 at 2:31pm UTC
It still doesn't work. I'm getting this error:
error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class CMArray<int> &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$CMArray@H@@@Z) referenced in function _wmain
Aug 3, 2010 at 2:36pm UTC
//Edit
I got this. I add:
template <class TT>
before friendship declaration in .h file. Now it works. I appreciate your help. Thanks.