| | |
operator<< overloading for a template class
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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
Views: 316 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project python random read recursion recursive reference return sort stream string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






