@andig i have no idea. sent a message on Espressif bbs: http://bbs.espressif.com/viewtopic.php?f=7&t=1781
Need a hand from some C++ gurus... trying to have a class that can call a variety of its own functions depending on which one is 'set'...
example
class foo {
public:
typedef std::function<void(int)> Callback; // define callback
void setcallback(Callback Fn) { _Callback = Fn; } // function used to set which function to call
void runcallback(int a) // function that calls what ever function is set by setcallback
{
_Callback(a);
}
void thefunction(int value) // one of any number of functions that can be called....
{
Serial.printf("yes %u\n", value);
}
void randomfunction() // random function that sets the callback function...
{
setcallback(thefunction);
}
private:
Callback _Callback; // stores the current function...
};
error
/Users/amelvin/Dropbox/Sketchbook/nah/nah.ino: In member function 'void foo::randomfunction()':
nah:18: error: no matching function for call to 'foo::setcallback(<unresolved overloaded function type>)'
setcallback(thefunction);
^
/Users/amelvin/Dropbox/Sketchbook/nah/nah.ino:18:28: note: candidate is:
/Users/amelvin/Dropbox/Sketchbook/nah/nah.ino:6:8: note: void foo::setcallback(foo::Callback)
void setcallback(Callback Fn) { _Callback = Fn; } // function used to set which function to call
^
/Users/amelvin/Dropbox/Sketchbook/nah/nah.ino:6:8: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'foo::Callback {aka std::function<void(int)>}'
exit status 1
no matching function for call to 'foo::setcallback(<unresolved overloaded function type>)'
tried for a few hours... just missing some C++ spice.. to get it right any ideas?
using namespace std::placeholders;
class foo {
public:
typedef std::function<void(int)> Callback; // define callback
void setcallback(Callback Fn) { _Callback = Fn; } // function used to set which function to call
void runcallback(int a) // function that calls what ever function is set by setcallback
{
_Callback(a);
}
void thefunction(int a) // one of any number of functions that can be called....
{
Serial.printf("yes \n");
}
void randomfunction() // random function that sets the callback function...
{
setcallback(std::bind(&foo::thefunction, this, _1));
}
private:
Callback _Callback; // stores the current function...
};