operator<< overloading for a template class

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 40
Reputation: seanhunt is an unknown quantity at this point 
Solved Threads: 6
seanhunt seanhunt is offline Offline
Light Poster

operator<< overloading for a template class

 
0
  #1
Aug 2nd, 2009
Folks,

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

  1. template<class T = double> class Real
  2. {
  3. T m_value;
  4. public:
  5. Real( T val = 0 ){
  6. m_value = val;
  7. }
  8. T get() const {
  9. return m_value;
  10. }
  11. };

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

Halp!

Thanks...
Sean
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,425
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 184
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso

Re: operator<< overloading for a template class

 
0
  #2
Aug 2nd, 2009
which part of overloading the << operator are you having
trouble with?

your prototype could be something like this :
  1. std::ostream& operator<<(std::ostream& os, Real<T>& real);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC