"no instance of overloaded function "mbed::Ticker::attach" matches the argument list" in file "cfExtensions//cfExtensions.cpp", Line: 69, Col: 37

31 Oct 2012

Hi all. I have been pulling my hair out trying to fix this error. I manage to fix all but this error:

"no instance of overloaded function "mbed::Ticker::attach" matches the argument list" in file "cfExtensionscfExtensions.cpp", Line: 69, Col: 37

in my main.cpp file I have:

#include "mbed.h"
#include "MODSERIAL.h"
#include "msExtensions.h"
#include "cfExtensions.h"

MODSERIAL pc(USBTX, USBRX);
msExtensions msAccess(&pc);
    
cfExtensions cfAccess(&msAccess);

int main()
{ 
    while(1) {

    }
}

In my cfExtensions.cpp file where that error resides:

void cfExtensions::checkConfigForFirstStart() {
    /*
     * Get a configuration value.
     */
    if (_cfg.getValue(cfExtensions::sbFirstStartKey, &cfExtensions::sbFirstStartValue[0], sizeof(cfExtensions::sbFirstStartValue))) {
        if (strcmp(&cfExtensions::sbFirstStartValue[0], "TRUE") == 0) {
            //someText = "PING!";
            //_msAccess->sendSomething(sbNameValue);
            pingTick.attach(&_msAccess, &_msAccess->sendSomething(cfExtensions::sbNameValue), 10);

            while(!_pc->readable()) {
                if (cfExtensions::pingTicked) {
                  cfExtensions::pingTicked = false;
                }
            }
            
            if(_pc->readable()) {
                pingTick.detach();
            }
            
            _cfg.setValue("FirstStart", "FALSE");
            _cfg.write("/local/settings.cfg");
        }
    }
} // End of checkConfigForFirstStart
<</code>

The sendSomething method resides in msExtensions.cpp file:
<<code>>

void msExtensions::sendSomething(char* txt) {
    printf("{\"sbPing\": \"%s\"}\r\n", txt);
} // End of pingBaseStation function
<</code>>

I have included the appropriate header files in both csExtensions and msExtensions classes. I did instantiate the Ticker object in the cfExtensions.h file like so:
<<code>>
public:
//---------------------------
// Declare Public Functions
//---------------------------
        Ticker       pingTick;           //Declare Ticker object

In regards to the Ticker object, I am not exactly sure if that is a good place to instantiate the pingTick object. I did read the Ticker api, but am still a bit rusty at understanding the api. I also read the section about how to use the method within a class, which lead me to the code that I wrote. The method code example shows & next to the address of the object and the member function. When I incorporated the & I arrived at another error: "expression must be an lvalue or a function designator" in file "cfExtensionscfExtensions.cpp", Line: 69, Col: 41. That error I believe was thrown due to code: &_msAccess->sendSomething(cfExtensions::sbNameValue). I am now ultimately confused. How do I fix my coding error so Ticker works effectively?

31 Oct 2012

When code becomes larger it can be easier to publish the program and drop the link to the published program here, then people can also try compiling it.

Now the problem seems to be that you attach a to the ticker a function which requires an argument. You may only attach functions which dont take arguments and which dont return any. So in this case you probably have to add a function 'send' in cfExtensions, which then calls the function you now attached to pingTick.

04 Nov 2012

Hi Erik! Sorry I am a bit delayed with a response. Moving to a new place got in the way of my mbed project. Anyways, here is the link to my published project: http://mbed.org/users/d0773d/code/Sensors/ As you recommended, I did add a function to my cfExtensions library and pointed the ticker to that new function instead of the function requiring an argument; however, I am still receiving errors. It might be easier to compile the project for yourself to view the errors. Please have a look and thanks in advanced!

04 Nov 2012

Hey,

Looked a bit at it, and two things: First your attach of the ticker was wrong syntax, see this topic: http://mbed.org/forum/mbed/topic/1127/?page=1#comment-8194

So in cfExtensions.cpp, line 73 becomes (note: I might have moved some stuff, so it could be one line less or more):

pingTick.attach(this, &cfExtensions::msSendSomething, 10);

Other error is one of those small, irritating to find ones, line 44 you forgot to add the 'cfExtensions::' in front of the function name. Result is that it doesnt recognize it as a function belonging to the class, so it doesnt get access to its variables, resulting in the error you saw.

Btw in the next line you can simplify it to:

_msAccess->sendSomething(sbNameValue);
04 Nov 2012

That was an extremely simple fix. I keep forgetting about the, for example, cfExtensions::somefunction bit. The code compiles. When I get home from work I will upload it to the mbed and see if does what I expect.