I
Ioannis Vranos
I am experimenting with a template class:
#include <iostream>
template <class Value_type>
class only
{
Value_type m_value;
template<class U> only(U);
public:
typedef Value_type value_type;
typedef Value_type& reference;
only(value_type value): m_value( value ) { }
value_type value() const { return m_value; }
std:stream & operator<<(std:stream &);
};
template <class Value_type>
std:stream & only<Value_type>:perator<<(std:stream &objOstream)
{
objOstream<< m_value;
return objOstream;
}
int main()
{
using namespace std;
only<int> obj= 10;
obj.operator<<(cout); // This works
}
Why cout<< obj; doesn't work? Is it a compiler issue?
#include <iostream>
template <class Value_type>
class only
{
Value_type m_value;
template<class U> only(U);
public:
typedef Value_type value_type;
typedef Value_type& reference;
only(value_type value): m_value( value ) { }
value_type value() const { return m_value; }
std:stream & operator<<(std:stream &);
};
template <class Value_type>
std:stream & only<Value_type>:perator<<(std:stream &objOstream)
{
objOstream<< m_value;
return objOstream;
}
int main()
{
using namespace std;
only<int> obj= 10;
obj.operator<<(cout); // This works
}
Why cout<< obj; doesn't work? Is it a compiler issue?