Re: Questing regarding returning of new objects
On 2007-09-09 14:58, vswathisai@gmail.com wrote:
hi,
what's my query is what's the full neccessity for operator
overloading.Why we are adopting this concept.there is often lies a
complexity working with this concept.
There is no necessity in operator overloading, but by using it we can
simplify the *usage* of the types we design. And just as you say it does
add a little extra complexity when writing the code for the type, but
generally no more than using normal functions would. But the important
thing to remember is that is can greatly simplify the usage of classes,
just look at std::complex. You can use them more or less just like a
normal arithmetic type when you write expressions. Lets take a look at
what the code would look like if you do not have operators for the
following expression:
a = b + c * (d - e / f) * g;
Would be something like:
a = b.add(c.multiply(d.minus(e.devide(f))).multiply(g));
or
a = add(b, multiply(multiply(c, minus(d, divide(e,f)) , g)));
I am not sure I got the second one correct, might have misplaced a
parenthesis, or perhaps even a whole sub-expression. Both of the
expressions that don't use operators take more to write, are harder to
tell what they do, and are harder to write.
Can anyone explain what are all the easy ways to getting the idea
about Runtime POLYMORPHISM.
You should start a new thread for this question, but performing a search
on google might be a better idea, or search the group archives.
--
Erik Wikstr?m