IT Community - Software Programming, Web Development and Technical Support

Overloadin

This is a discussion on Overloadin within the C and C++ Programming forums, part of the Software Development category; Anyone here know about operator overloading? Please point me to some tutorial or code snippets for operator overloading....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-24-2007, 12:50 AM
ewriter ewriter is offline
D-Web Trainee
 
Join Date: Apr 2007
Posts: 19
ewriter is on a distinguished road
Default Overloadin

Anyone here know about operator overloading? Please point me to some tutorial or code snippets for operator overloading.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-24-2007, 06:09 AM
pranky pranky is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 51
pranky is on a distinguished road
Default Re: Overloadin

lol coding snippets is not a big deal for me bro u can always ask me where to put in trouble.i will help u out..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-24-2007, 06:11 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Re: Overloadin

One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is called operator overloading. You can implement C++ operator overloads by providing special member-functions on your classes that follow a particular naming convention. For example, to overload the + operator for your class, you would provide a member-function named operator+ on your class.

The following set of operators is commonly overloaded for user-defined classes:

= (assignment operator)
+ - * (binary arithmetic operators)
+= -= *= (compound assignment operators)
== != (comparison operators)

C++ allows almost all operators to be overloaded, i.e.their meanings can be redefined for different objects. But Cannot introduce new operators only overload existing ones. So cannot create the exponentiation operator **
as in some languages.

These C++ operators may not be overloaded

:: scope resolution operator
sizeof operator
. object member selection
.* pointer to member obj.*member
: ? conditional expression

At least one of the arguments must be a user-defined type.

So for '+':

Person + Person O.K.
Person + int O.K.
int + int Not O.K since that would redefine meaning of addition for primitives

For example
class MyClass
{
public:
...
MyClass & operator=(const MyClass &rhs);
...
}

MyClass a, b;
...
b = a; // Same as b.operator=(a);
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Karpagarajan : 04-24-2007 at 06:17 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-24-2007, 11:19 PM
im2good im2good is offline
D-Web Trainee
 
Join Date: Apr 2007
Posts: 20
im2good is on a distinguished road
Default Re: Overloadin

Pretty much easiest topic
Could you pinpoint to me where you are having problem with operator overloading
I may help you in it
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 07:33 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0