C++ Program For Pre Increment and Decrement Operator Overloading
Free C++ course with real-time projects Start Now!!
Program 1
//Unary Operator overloading (- operator) #include<iostream> #define clrscr() system("cls") using namespace std; class Test { int a,b,c; public: Test(int a,int b,int c) { this->a=a; this->b=b; this->c=c; } void display(); void operator++(); void operator--(); }; void Test::operator++() { ++a; ++b; ++c; } void Test::operator--() { --a; --b; --c; } void Test::display() { cout<<"\n"<<a <<" "<<b<<" "<<c; } int main() { clrscr(); Test T1(10,20,30); T1.display(); cout<<endl; ++T1; //T1.operator++() //--T1; //T1.operator--() T1.display(); return 0; }
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google