Created
June 20, 2020 15:43
-
-
Save javedbaloch4/f245e1ecf7cb9ceb325e4a424b348360 to your computer and use it in GitHub Desktop.
C++ overloading cout's << operator for length class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Written by Javed Ahmed - F2019266402 | |
| #include <iostream> | |
| using namespace std; | |
| class Length | |
| { | |
| private: | |
| int distance; | |
| public: | |
| Length(){ | |
| this->distance = 0; | |
| } | |
| Length(int distance){ | |
| this->distance = distance; | |
| } | |
| friend ostream& operator << (ostream& out, Length& op); | |
| }; | |
| ostream& operator << (ostream& out, Length& op){ | |
| cout << "The Total Length is = "; | |
| out << op.distance << endl; | |
| return out; | |
| } | |
| int main() | |
| { | |
| Length d(45); | |
| cout << d << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment