Ticker function calls confusion

05 Sep 2009

As a newbie CPP programmer, I am confused about the two methods of attaching a function in ticker - ie direct and template with member function. The *ptr variable seems to be called in various examples sometimes by '&name' and sometimes just by 'name'. I'm sure this must all be obvious to experienced CPP programmers, but where can I find a clear explanation of how this works?

Tony

05 Sep 2009

Hi Tony,

Tony Abbey wrote:
As a newbie CPP programmer, I am confused about the two methods of attaching a function in ticker - ie direct and template with member function. The *ptr variable seems to be called in various examples sometimes by '&name' and sometimes just by 'name'.

I've just updated http://mbed.org/handbook/Ticker with an example for attaching a static function (normal function) and a member function (function on a particular object instance).

Details: The & before a function name means you are passing the address of the function, which is the correct form. However, because using the function name alone doesn't make sense as a variable, most compilers will accept just name, and treat it as if you had written &name.

Do these updated examples help? This sort of feedback is wonderful btw.

Simon

06 Sep 2009

Hi Simon

Thanks for taking the time to update the examples. I understand what you say about function addressing etc, but I am still confused by the member function code. Could you answer the following questions, please (and even then I probably wont get it, having been an engineer for too long - an old style hacker/programmer):

1. What is the purpose of the member function method?

2. In 'Flipper' why does your pinname start with a '_' ?

3. Why is class Flipper public, but DigitalOut private?

 4. In t.attach I can see that &f is the address of the Flipper code, but I can't see what the member function &Flipper::flip does

Tony