Is it possible to replace an operator with a variable in C++?
In other words instead of…
++ Foo;
Could I use…
int var = ++;
Then…
var Foo;
In other words instead of…
++ Foo;
Could I use…
int var = ++;
Then…
var Foo;
Last edited:
We need more context because the above command isn't syntactically correct.Could I use…
int var = ++
Even if you could do what you want, what has it bought you? Once you know the direction you would still need to change the code and recompile.Because...
I need to change a PWM value to a new value using a loop (step), but I wont know whether I need to increment or decrement the value until its ready to change, so I was hoping I could change the operator as needed after determining the direction.
You could set var to either plus or minus 1, then do 'foo + var' which will either increment or decrement foo.Because...
I need to change a PWM value to a new value using a loop (step), but I wont know whether I need to increment or decrement the value until its ready to change, so I was hoping I could change the operator as needed after determining the direction.
It depends.So the bottom line is, changing a operator on the fly is a big no-no.
It's like Self-modifying code. It has a place but I don't think this is one of them.So the bottom line is, changing a operator on the fly is a big no-no.
That's what we're for.When it comes to coding what is important to me is...doing the job and keeping it simple. I'm not married to any particular way of doing something but with my lack of experience it can take quite a long time to come up with any method, so I need to find out issue by issue which ones work and which ones wont.
And I thank you all.
by Jake Hertz
by Aaron Carman
by Jake Hertz
by Aaron Carman