Total members 11892 |It is currently Fri Oct 18, 2024 9:19 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This an easy code for operating overloading.
cpp 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;
}




_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time

Thanks :gOOd:

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 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:

_________________
Please recommend my post if you found it helpful. ,
java,j2ee,ccna ,ccnp certified .


Author:
Expert
User avatar Posts: 838
Have thanks: 2 time

updated.

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 4 posts ] 

  Related Posts  to : Operator overloading easy code
 operator overloading     -  
 What is Operator Overloading? !!!     -  
 unary operator overloading     -  
 overloading << and >>     -  
 Function Overloading     -  
 how to build a rating bar in easy and quick way in website     -  
 operator int()     -  
 Using the ? Operator     -  
 What is the % operator     -  
 Sizeof Operator     -  



Topic Tags

C++ OOP






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com