[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2010-08-27
6
Medium Priority
?
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Accepted Solution

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

Expert Comment

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

Author Comment

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

Assisted Solution

by:evilrix
evilrix earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 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