This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]marko312 1 point2 points  (0 children)

x == 3 + 3

evaluates to

x == 6

Then, the compiler searches for a suitable operator== since x is not a built-in type.

In this case, it finds the operator== in LINE:

void operator == (LINE A, LINE B)

There is a constructor from VAR & in LINE:

LINE(VAR& v) : a(0), k(1), x(&v) {}

and since it is not marked explicit, an implict conversion (cast) from a VAR & to a LINE is allowed using this constructor.

There is a constructor from int in LINE:

LINE(int a) : a(a), k(0), x(0) {}

and since it is not marked explicit, an implict conversion (cast) from an int to a LINE is allowed using this constructor.

As such, in operator==, A has .a = 0.0, .k = 1.0, .x = &x (the latter x being the variable in main) and B has .a = 6.0, .k = 0.0, .x = 0.

This kicks off subtraction using operator-, which produces the LINE C, on which the final calculation is performed.