| | |
operator<< overloading for a template class
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 40
Reputation:
Solved Threads: 6
Folks,
I'm having some trouble with overloading the '<<' operator for a templated class. For example, given a very simple template class like this:
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
I'm having some trouble with overloading the '<<' operator for a templated class. For example, given a very simple template class like this:
C++ Syntax (Toggle Plain Text)
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 <complex> header but I really want a simpler block than that. The template parameter could be int, float, etc.
Halp!
Thanks...
Sean
which part of overloading the << operator are you having
trouble with?
your prototype could be something like this :
trouble with?
your prototype could be something like this :
C++ Syntax (Toggle Plain Text)
std::ostream& operator<<(std::ostream& os, Real<T>& real);
![]() |
Similar Threads
- correct [] operator overloading in template class (C++)
- Operator overloading with nested and templated classes (C++)
- Linked List Class - Operator Overloading (C++)
- help me to do operator overloading n class (C++)
- C++ Tic Tac Toe using classes & operator overloading (C++)
Other Threads in the C++ Forum
- Previous Thread: classes
- Next Thread: life simulation project
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






