Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Expression: a1+a2*a3/a4

While a1,a2,a3,a4 are the objects

What I have tried:

I wrote different operator functions for separate operators like one function for + operator and another for * operator... But it's not work...
Posted
Updated 13-Aug-19 8:52am
Comments
Richard Deeming 13-Aug-19 13:28pm    
You haven't described a problem, or shown us what you've tried, or given us any details of the errors you're getting.

Click the green "Improve question" link. Update your question with a full description of the problem you're trying to solve, the relevant parts of the code you've tried, and the full details of any errors. Remember to indicate which line of code the errors relate to.
Rick York 13-Aug-19 14:22pm    
Did you implement the / operator also? You have +, *, and / operations there. You might as well add the - operator also, both binary and unary.
KarstenK 13-Aug-19 14:29pm    
Read the language documentation carefully. The operators need to be public member function with reference syntax.

Good luck! It works ;-)

PS: if not than show us the code.

You forgot to specify the nature of the objects.
Anyway have a look at this page operator overloading - cppreference.com[^], see the binary arithmetic operators section for sample code.
 
Share this answer
 
Quote:
I wrote different operator functions for separate operators like one function for + operator and another for * operator... But it's not work...

Even with best will, the answer is "You did it wrong".
You gave absolutely nothing to work on. You did not even told how it 'not work', is it wrong result or compile fail ?

To get help, show related code and describe whet is 'But it's not work'
and give example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900