Is it possible to make a class for operators? IE:
Code:
Operator A = +;
int B, C;
B = (B A C);
The only reason I want to do this, is to avoid having long if statements that do the same thing only a slight change to operators
Code:
Operator A = +;
int B, C;
if(B > 0)
a = -;
B = (B A C);
As opposed to:
Code:
int B, C:
if(B > 0)
B = B - C;
if(B <= 0)
B = B + C;
Now, thats pritty simple code that I wouldent mind doing. They are both 5 lines, the same amount of work. But, when I want something like:
Code:
int A, B, C;
if(A < 0 && B > 0) {
A += 1;
A = (B + C) / A;
B += 1;
B = (C - A) / B;
C = (C << 2) / A;
}
if(A > C && B > C) {
A += 1;
A = (B - C) / A;
B += 1;
B = (C - A) / B;
C = (C << 2) / A;
}
Instead of making a whole new IF and make the same code twice, it would be ten times easier to do:
Code:
Operator O = -;
int A, B, C;
if(A < 0 && B > 0)
O = +;
A += 1;
A = (B O C) / A;
B += 1;
B = (C - A) / B;
C = (C << 2) / A;
Basicaly, I'm just trying to cut down on uncessisary lines of code. Though, I realize (B O C) would be very ugly. (Would seem more like you wanted to multiply the three) But, is there some way to do this? Even if its some hackish define? (#define M (A, B) (A < 0) + (A > 0) -) I know thats not a real define (Never made a define macro)
Well, if its possible by some means, it'd be great.
Thanks!