Operator overloading
Operator overriding
Function overloading
Here I m discussing operator overloading:
Usually an operator can be operated on built in data types like int, float. But if you want to operate the operators available in C++ on user defined data type like object, then it can be done by operator overloading. By operator overloading we can make an operator to operate on user defined variables. Operator overloading includes following features:
Only existing operator can be overloaded
It will not change the basic meaning of operator
Overloaded operator will follow the same syntax rule of the original operator
There are some operators that can't be overloaded
Unary operators, overloaded b y means of a member function, take no explicit arguments and return no explicit argument. The syntax for member function for overloading unary operator is:
operator op ()
{
Statement........
}
Here return type is the data type of the value we want to return from this member function. Operator is the keyword and op is the operator to be overloaded (like in this case it will be ++) and like other member functions we can have parameter list also. ++ Operator will simply increment the value of the variable. It can be either prefix or postfix. This can be called through variables like: "a++" or "++a". for a object obj1 of class length we can use this operator like:
Obj1++;
And the member function for it will be like:
Void operator ++ (........)
{......... ............ ................ }
We don't have to pass the variables explicitly it will be automatically passes implicitly. The object will be passed implicitly and we will simply increment all the variables under object "obj1" and the control will be returned back to the main function. So by this you can easily use increment operator on user defined object. Hence you can easily implement operator overloading on unary operator.
Problems on operator overloading of unary "++" operator:
This overloading can be done on pre increment operator but, it will generate a warning when we implement it on post increment operator. But it will perform the pre and post increment operator. We can't distinguish between pre and post increment operator as it will do the same. We can't make it differ to perform pre and post increment.
Published by Harsh Gupta - Tech Writer
I am a part time freelancer and writing is my hobby Some of my websites: http://www.GenericArticles.com http://www.JailBreakingiPhone.com View profile
Review of the Pledge Duster PlusA review of the new Pledge Duster Plus with multi purpose spray. Will it perform as it's advertised to? Does it really clean any surface?- How to Shop for Plus Sized Women's ClothingFor Plus Size Women - How to Dress to Look Your Best. In this article we'll explore some hints and tips for how to buy the right clothes to compliment your plus sized frame.
- Embracing Fashion as a Plus Size WomenFashion is changing our perceptions about weight and beauty. As a plus size woman, learn to embrace your beauty and express your bodily image through fashion proudly.
- Where to Gete Cheap Plus Size Prom DressesYour prom dress is just as important as going to prom itself. For some girls finding the perfect dress is easy. However, finding the perfect dress if your a plus size girl is more of a challenge
- Plus Size Teen Clothing StoresIf you are a plus sized teen you may find it frustrating to shop and find 'cool and hip' clothing. Here I will show you a few online clothing stores and a few nationwide clothing stores that specialize in plus size te...
- Pert Plus: The Perfect Shampoo for Kids
- Find Great Plus Size Workout Wear
- Shopping for Women's Plus Size Clothing
- Razor Burn is a Thing of the Past - Schick Intuition Plus Razor: A Product Review
- Plus Size Fashion for Teens: An Overview
- Holiday Plus Size Clothing Store Guide
- Plus Size Fashion Designers to Admire
- By operator overloading we can make an operator to operate on user defined variables.



