Solved

How to create a c++ operator ? (like + - * )

Posted on 2010-08-27
6
350 Views
Last Modified: 2012-05-10
Hello, I miss some bases in c++ and a thing would help me is to be able to create operator to do some operation between custom variables.
For example:
struct quote
{
  float number;
  int coeff;
}
quote var1, var2;
...
quote result=var1+var2;

Open in new window

to have the "+" multiply the number and coeff before adding the to product.

Thanks
0
Comment
Question by:Greg2FS
6 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 33540826
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33540943
Why is this in Java?
0
 

Author Comment

by:Greg2FS
ID: 33540949
Because I thought it was similar in java...
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 250 total points
ID: 33540982
Two good resources on how to do operator overloading.

"Overloading operators"
http://www.cplusplus.com/doc/tutorial/classes2/

"Operator Overloading"
http://msdn.microsoft.com/en-us/library/5tk49fh2(VS.80).aspx
0
 
LVL 32

Expert Comment

by:phoffric
ID: 33541131
I'm not sure where my previous post went. Repeating it...Here is a good resource for operator overloading:    http://www.java2s.com/Tutorial/Cpp/0200__Operator-Overloading/Catalog0200__Operator-Overloading.htmHope it sticks this time.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now