c_-_c_operator_overloading:binary_operator_overloading
C - C++ Operator Overloading - Binary Operator Overloading
#include<iostream> using namespace std; class overload { float a,b; public: overload() { } overload(float v1,float v2) { a=v1; b=v2; } void print(); friend overload operator +(overload x,overload tempvar); }; void overload::print() { cout<<a<<"+j"<<b; } overload operator +(overload x,overload tempvar) { tempvar.a=tempvar.a+x.a; tempvar.b=tempvar.b+x.b; return(tempvar); } int main() { overload obj1,obj2,obj3; obj1=overload(1.2,1.2); obj2=overload(1.4,1.4); obj3=obj1+obj2; cout<<"\nobj1="; obj1.print(); cout<<"\nobj2="; obj2.print(); cout<<"\nobj3="; obj3.print(); return 0; }
c_-_c_operator_overloading/binary_operator_overloading.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1