| | |
operator overloading
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
usually :
note overloading the << operator should be a friend, so you can use it like this :
cout << myClassVar;
if not then you would use this syntax :
myClassVar <<cout;
which is confusing.
C++ Syntax (Toggle Plain Text)
std::ostream& operator <<(std::ostream& ostrm) { ostrm << "Hello its overloaded\n"; return ostrm; } std::istream& operator >>(std::istream& istrm) { cout<<"Enter a number : "; istrm >> MyClass::myNumber; return istrm; }
note overloading the << operator should be a friend, so you can use it like this :
cout << myClassVar;
if not then you would use this syntax :
myClassVar <<cout;
which is confusing.
Last edited by firstPerson; Aug 21st, 2009 at 2:59 pm.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
•
•
Join Date: Sep 2009
Posts: 3
Reputation:
Solved Threads: 0
i too have and still have problems with operator overloading, i found the following website helpful. i hope that it does the same for you.
http://www.learncpp.com/cpp-tutorial...tic-operators/
http://www.learncpp.com/cpp-tutorial...tic-operators/
![]() |
Similar Threads
- a small prob with operator overloading (C++)
- Operator Overloading HELP! (C++)
- about operator overloading (C++)
- operator overloading (Java)
- Operator Overloading Question (C++)
- C++ Tic Tac Toe using classes & operator overloading (C++)
- program for finding factorial of a number using *operator overloading (C++)
Other Threads in the C++ Forum
- Previous Thread: Convert paper money into coins.
- Next Thread: Double linked List Iterator InsertAfter Function
Views: 356 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph 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 search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






