184. Write a program to overload assignment operator over object explicitly?

#include<iostream.h> #include<conio.h> class assign { private:                 int a,b; public:                 assign(int p,int q)                                 {                                 a=p;                                 b=q;                                 }                 void operator=(assign obj)                                 {                                 a=obj.a;                                 b=obj.b;                                 }                 void display()                                 {                                 cout<<"A = "<<a<<"\tB = "<<b<<endl;                                 } }; void main() {                 clrscr();                 assign... Continue Reading →

Advertisements

183. Write a program to overload assignment operator over object implicitly?

#include<iostream.h> #include<conio.h> class assign { private:                 int a,b; public:                 assign(int p,int q)                                 {                                 a=p;                                 b=q;                                 }                 void display()                                 {                                 cout<<"A = "<<a<<"\tB = "<<b<<endl;                                 } }; void main() {                 clrscr();                 assign x(5,3),y(2,4);                 x.display();                 y.display();                 y=x;       //Implicit Operator Overloading                 cout<<"After... Continue Reading →

182. Write a program to overload postfix increment operator over an object using member function?

Note: - If operator function as member function then in the case with postfix increment or decrement. We must specify (int) keyword inside the parenthesis of operator function. #include<iostream.h> #include<conio.h> class increment { private:                 int a,b; public:                 increment(int p,int q)                                 {                                 a=p;                                 b=q;                                 }                 void display()                                 {... Continue Reading →

181. Write a program to overload postfix increment operator over an object using friend function?

#include<iostream.h> #include<conio.h> class increment { private:                 int a,b; public:                 increment()                                 {                                 }                 increment(int p,int q)                                 {                                 a=p;                                 b=q;                                 }                 void display()                                 {                                 cout<<"A = "<<a<<"\tB = "<<b<<endl;                                 }                 friend increment operator ++ (increment obj); }; increment operator ++ (increment obj) {... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: