Write a programme in c++ to Overload << operator using friend function.
#include<iostream>
using namespace std;
class Overload{
public:
int x, y;
friend ostream &operator<<(ostream &output, const Overload &D);
};
ostream &operator<<(ostream &output, const Overload &D){
output<<"X is: "<<D.x<<"Y is: "<<D.y<<endl;
}
int main(){
Overload O;
O.x = 6;
O.y = 9;
cout<<O<<endl;
}
Comments
Leave a comment