Click here to Skip to main content
14,265,815 members
Rate this:
Please Sign up or sign in to 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 4 days ago
Comments
Richard Deeming 4 days ago
   
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 4 days ago
   
Did you implement the / operator also? You have +, *, and / operations there. You might as well add the - operator also, both binary and unary.
KarstenK 4 days ago
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100