S
Surya Kiran
Hi all,
I've a class template, of which i've an overloaded operator (operator
<<) which was written like this
=============== classa.hpp ===========
template <class T>
class A
{
....
....
friend ostream& operator<< (ostream&, const A<T>&)
}
======================================
and the implementation like this
==== classa.cpp =====
template <class T>
ostream& operator<< (ostream& os, const A<T>& t)
{
....
....
}
======================
When i compile this one, i'm getting errors
saying undefined reference to ostream& operator<< <int> instance (i've
created <int> instance of class A.). What is the correct way to
declare and define an overloaded operator like << to a class template.
One thing i've observed is when i give the definition of the
overloaded operator in the header file itself, its working fine. what
could have been the problem.
Thanks in advance,
Surya
I've a class template, of which i've an overloaded operator (operator
<<) which was written like this
=============== classa.hpp ===========
template <class T>
class A
{
....
....
friend ostream& operator<< (ostream&, const A<T>&)
}
======================================
and the implementation like this
==== classa.cpp =====
template <class T>
ostream& operator<< (ostream& os, const A<T>& t)
{
....
....
}
======================
When i compile this one, i'm getting errors
saying undefined reference to ostream& operator<< <int> instance (i've
created <int> instance of class A.). What is the correct way to
declare and define an overloaded operator like << to a class template.
One thing i've observed is when i give the definition of the
overloaded operator in the header file itself, its working fine. what
could have been the problem.
Thanks in advance,
Surya