Go Down

Topic: Pushbotton Counter (Read 675 times) previous topic - next topic

PaulS

Quote
You might think so but due to the use of the conversion operator 'operator uint8_t()' it can, and does, work just fine.

In most cases, operators are defined to make a class behave in a manner that the users expect. For instance, one would, in a string class, overload the + operator, or, for a list class, one would overload the {} operator.

I don't see a reasonable use for the () operator in a button class. One does not expect an instance name by itself to be equivalent to a function call. Adding a method to the class, with a meaningful name to get that value returned by the () operator is a MUCH better idea, in my opinion.

lloyddean

And yet this is exactly what conversion operators are for.  They are a type of 'getter' function.

johncc

If you are going to have a conversion operator, is there any reason not to provide conversion to bool instead of to uint8_t?

Or is this just me still having mental problems with digitalWrite( int,int) vs  digitalWrite( int, bool)

PaulS

Quote
Or is this just me still having mental problems with digitalWrite( int,int) vs  digitalWrite( int, bool)

For that matter, are there really plans to create an Arduino with more than 255 pins? Does digitalWrite() need to use an int as the pin number?

lloyddean

'digitalWrite' uses 'uint8_t' for both parameters.  And yes other conversion operator can be defined.

Go Up