Operator Overloading:-Operator Overloading provides option for creation of new definition of Operators.Operator overloading provide special meaning to most of the operator like =,+,-,*,=+,== etc. but expect some operator.It is used in c ++,java,c#(c sharp) etc.
Some exception operators are:-
1)Scope Resolution Operator(::)
2)Sizeof operator
3)Conditional Operator(?:)
4)Class member access point
5)Value of (*.)
Example:-Write a program to overload the unary operator "-"(you can also overload binary operator).
# include<iostream.h>
void<conio.h>
class xyz
{
int p,q,r;
public:
void get();
void put();
void operator-();
};
void xyz::get()
{
cout<<"enter no.";
cin>>p>>q;
}
void num::put()
{
cout<<p<<q<<r;
}
void xyz::operator-()
{
p=-p;
q=-q;
r=-r;
}
void main()
{
xyz x; //object
clrscr();
x.get();
x.put();
-x;
x.put();
getch();
}
That's all about Operator Overloading(in oops and data structure).
Some exception operators are:-
1)Scope Resolution Operator(::)
2)Sizeof operator
3)Conditional Operator(?:)
4)Class member access point
5)Value of (*.)
Example:-Write a program to overload the unary operator "-"(you can also overload binary operator).
# include<iostream.h>
void<conio.h>
class xyz
{
int p,q,r;
public:
void get();
void put();
void operator-();
};
void xyz::get()
{
cout<<"enter no.";
cin>>p>>q;
}
void num::put()
{
cout<<p<<q<<r;
}
void xyz::operator-()
{
p=-p;
q=-q;
r=-r;
}
void main()
{
xyz x; //object
clrscr();
x.get();
x.put();
-x;
x.put();
getch();
}
That's all about Operator Overloading(in oops and data structure).
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.
You made some good points there. I did a search on the topic and found most people will agree with your blog.Python Training in Chennai
ReplyDelete