954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

operator<< overloading for a template class

Folks,

I'm having some trouble with overloading the '<<' operator for a templated class. For example, given a very simple template class like this:

template<class T = double> class Real
	{
		T	m_value;
	public:
		Real( T val = 0 ){
			m_value = val;
		}
		T get() const {
			return m_value;
		}
	};


This class rests inside a namespace. I've looked at the code in the header but I really want a simpler block than that. The template parameter could be int, float, etc.

Halp!

Thanks...
Sean

seanhunt
Light Poster
40 posts since Oct 2008
Reputation Points: 13
Solved Threads: 6
 

which part of overloading the << operator are you having
trouble with?

your prototype could be something like this :

std::ostream& operator<<(std::ostream& os, Real<T>& real);
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You