Click here to Skip to main content
15,905,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Like let's say -

A a1,a2,a3,a4;


Assuming there is a class A and *,+,post increment operator(++) and / are overloaded in class A. a1,a2,a3,a4 are objects of A class.

So what's the order of evaluation of operators in above expression -

If we'll check according to the precedence of operators then * will be evaluated first then / then + and last post increment(++). But I have overloaded multiple operators but they are not working according to the precedence.

Please tell.

What I have tried:

Tried googling and also did experiment but still didn't understand.
Updated 29-Oct-22 14:02pm

Share this answer
Share this answer
Whether they've been overloaded or not, the compiler generates code to execute operators in the same order.

If you read the page that Richard linked, I think you'll discover that you're mistaken about the order in which the evaluation occurs for this expression. In any case, I would never write that kind of expression without including parentheses to make the evaluation order clear. There is no prize for eliminating a few keystrokes, notwithstanding some of the "clever" code that you will occasionally see.
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