# Thread: overloading, L-value and deference operators...

1. ## overloading, L-value and deference operators...

Hey everyone...

Well, this semester I entered in an AP computer science class (without previous knowledge of what I was getting myself into...) and some classmates and I have to explain to the class in simple, "English" terms about overloading, L-value and deference operators. We are suppose to give an oral presentation and include examples as well as the explination of each topic. If anyone knows anything explaining these subjects, can you let me know or if there are any sites you know of, please tell me asap!!!

Thanks

P.S. I do not know THAT much about C++ and programming so please don't get too technical!!

2. I'll answer some of your crap for you:

Code:
`int x = 5;`
In this, x is the L Value and 5 is the R Value.

The golden rule about these two is thus:

The R values can never go on the left in this case.

Observe:
Code:
```int x = 5; // Correct

5 = int x; // What're you thinking? Ahh!```
And a dereference operator is *. It's important with pointers.

Observe:

Code:
```int Age = 5; // Initializes Age w/ value of 5
cout << Age; // Prints out Age's Value (5)
int * PointsToAge = &Age; // Creates pointer pointing to Age's memory address
*PointsToAge = 10; /*This is a bit tricky.
This is where
you use your pointer to manipulate your data.
This line can be read as
'Whatever this pointer (PointsToAge) is
pointing to is to be assigned to the value of 10.'
Since this particular pointer's
pointing to Age,
Age is re-assigned to the value of 10.*/
cout << Age; // This is proven here, when Age is printed once more. (10)```
I hope that helps

3. ## Some Insight Into Overloading

Overloading as the name suggest is trying to provide multiple methods with a single interface .... oops sounds technical is it.... hmmm let me make it simpler....

int x = 10 + 10;

Here the "+" operator adds two integers and the resultant (which happens to be int) is stored in x

double y = 10 + 20.2;

Here the same "+" operator adds one integer and another double and the resultant(which happens to be double) is stored in y.

If you closely observe, its the same + operator which is used in both the cases, but it's behaviour is different for different kind of operands. So you could say that + operator is overloaded.. in the sence its got more than one kind of behaviour.

You can overload functions too... called function overloading

4. Overloading

For example conside that you have a class called date.. This class might be used to do manipulation on date..

so you have an object of type date say d1;

you can overload the operator +, -,* etc to make stuff easier for you...

for example if you want to add certain number of days to the given date d1.. you have to call a function say...

d1=adddays(d1,10); or something like this.. but if you overload the operator + you can have it as d1=d1+10; or even d1=d1+d2;

This is very usefull in many programs..

Popular pages Recent additions