• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

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

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
Greg2FS
Asked:
Greg2FS
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
CEHJCommented:
Why is this in Java?
0
 
Greg2FSAuthor Commented:
Because I thought it was similar in java...
0
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
phoffricCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now