Total members 9936 | Gratitudes |It is currently Sun Feb 05, 2012 8:16 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 3 posts ] 
Author Question
 Question subject: Operator overloading easy code
PostPosted: Sun May 25, 2008 5:44 pm 
Offline
Beginner
User avatar

Joined: Sun May 25, 2008 5:34 pm
Posts: 95
Has thanked: 2 time
Have thanks: 1 time

This an easy code for operating overloading :yahoo:
Code:
//So now you ask, what is this operator overloading stuff, how will it help me make the supreme burrito, and what the heck does "binary operator overloading" mean? Lets take this one step at a time. First, a quick example of operator overloading.

#include <iostream.h>

class Burrito
{
  private:
    int amtbeef, amtbean;
  public:

    Burrito(int beef, int bean) {
      amtbeef = beef;
      amtbean = bean;
    }
    Burrito operator + (Burrito newburrito)
   {
      int newbeef = amtbeef + newburrito.amtbeef;
      int newbean = amtbean + newburrito.amtbean;
      return Burrito(newbeef, newbean);
    }
};

void main(void)
{
  Burrito b1(5,10), b2(10,5), b3;
  b3 = b1 + b2;

//  cout<<b3<<endl;
}




TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Operator overloading easy code
PostPosted: Sun May 25, 2008 5:56 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2101
Location: Earth
Has thanked: 39 time
Have thanks: 56 time
Thanks :gOOd:

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Operator overloading easy code
PostPosted: Sun May 25, 2008 6:28 pm 
Offline
Expert
User avatar

Joined: Tue Nov 06, 2007 2:17 pm
Posts: 847
Has thanked: 0 time
Have thanks: 1 time
operator overloading help programmer so much in data structure

like stack in this example

Stack outer_stack;
for (int i = 0; i < 1000000; i‚‚) {
Stack inner_stack;
inner_stack.push(some_data);
inner_stack = outer_stack;
}

can you figure out where will be the problem without using operator overloading? :club:

_________________
Any help needed just reply to my topic ,
ccna ,ccnp certified .


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 3 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Read your gmail using Java code  Java examples  msi_333  5
 What's wrong with my code?  Java  Anonymous  3
 project source code in java  Java  Anonymous  0
 Ajax Source code to Suggest application with JSP Server side  AJAX  msi_333  5
 java code to open word doc attached in ms access.db  Java  Anonymous  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google [Bot] and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team