I've got an assignment working with an encoder and a quadrature decoder/counter card - the thing I need a hand with is I'm required to overload the '!' operator such that when I write: '!MyEncoder', it resets all channels (there are 8).
I have a class with all required functions, such as ReadChannel(int channel) and ResetChannel(int channel), I'm just not exactly sure how I'd create the overload operator member function.
It doesn't need to return any value, it simply needs to perform a function (ie reset all channels) when '!MyEncoder' is input. I think that it requires an argument (int channel) which perhaps loops through all channels and resets them like that. I'm just confused as to how I would modify the functionality of '!'.
Any help/guidance is MUCH appreciated
(ps. if you'd like to see what i've done so far, i can upload the source code no problem)
Sounds like yet another teacher who is abusing the language. Overloading operators should be done with a bit of thought as to whether the usage you are putting it to chimes properly with its meaning. The ! operator mean 'not', not 'reset', so is a very bad choice for this usage.
In the real world, anyone coming across this usage, !MyEncoder, would need to check the code to see what it does. If it was simply MyEncoder.ResetAllChannels(), this would be obvious.
There are very few uses for overloading !, the only one I can think of being for a custom built boolean class or something similar. It's probably allowed in C++ more for completeness than anything else.
Please don't take this as a criticism of you, Absolute_N00b, I know you are just doing what your teacher tells you. But maybe mention this to them so they know better for next year!