Oh, yes?
Here's another way. Function objects:
// function object
typedef struct myObject
{
// constructor
myObject (const int value) : value_ (value) {}
// operator ()
void operator () (void)
{
Serial.print ("Value = ");
Serial.println (value_);
} // end of operator ()
private:
int value_;
};
void setup()
{
Serial.begin(115200);
myObject obj1 (42);
myObject obj2 (22);
myObject obj3 (55);
// call the function objects
obj1 ();
obj2 ();
obj3 ();
}
void loop() { }
Output:
Value = 42
Value = 22
Value = 55
In this case the object "behaves like" a function, except you can hold private variables (state). Quite a useful trick if you want multiple copies of a function that do the same thing but "remember" things between function calls.