Skip to content

Instantly share code, notes, and snippets.

@javedbaloch4
Created June 20, 2020 15:43
Show Gist options
  • Save javedbaloch4/f245e1ecf7cb9ceb325e4a424b348360 to your computer and use it in GitHub Desktop.
Save javedbaloch4/f245e1ecf7cb9ceb325e4a424b348360 to your computer and use it in GitHub Desktop.
C++ overloading cout's << operator for length class
// 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