Error: "invalid use of non-static member function" while calling a function from my own class-method I'm having a bad time trying to call a correctly-working expression (ultra[currentSensor].ping_timer(echoCheck)) from an own class method (myclass::run) instead of from void loop().

I'm getting the following compiler error:
"invalid use of non-static member function".

If I call ultra[currentSensor].ping_timer(echoCheck) directly from void loop() it gives me no error, so I may be missing something.

Here's the (shortened) piece of code which is generating the error:

#include &lt;NewPing.h&gt;

#define ULTRA_NUM      3
#define MAX_DISTANCE 200

class myclass {
  public:

    void run();
    void echoCheck();

    unsigned int distance[ULTRA_NUM];
    uint8_t currentSensor = 0;
};

NewPing ultra[ULTRA_NUM] = {
  NewPing(4, 5, MAX_DISTANCE),
  NewPing(6, 7, MAX_DISTANCE),
  NewPing(8, 9, MAX_DISTANCE)
};

void myclass::run() {
// ....
      ultra[currentSensor].ping_timer(echoCheck);  // Compiler error
  }

void myclass::echoCheck() {
  if (ultra[currentSensor].check_timer())
    distance[currentSensor] = ultra[currentSensor].ping_result
}


ping_timer() is defined as it follows:

void NewPing::ping_timer(void (*userFunc)(void), unsigned int max_cm_distance) {
    if (max_cm_distance &gt; 0) set_max_distance(max_cm_distance);

    if (!ping_trigger()) return;
    timer_us(ECHO_TIMER_FREQ, userFunc);
}


I hope any of you can help me!

Thanks in advance,

Eduardo



Edit:
What I am trying to do is to adapt this example (from NewPing Arduino Library) so that the sonar ping (sonar[currentSensor].ping_timer(echoCheck)) is done from a class method, and not from void loop().
The problem is that echo_check isn't void echo_check() but void echo_check(myclass *this) because it's a member function of a class.

You can make the whole thing static (along with run()) by:

class myclass {
    public:
        static void run();
        static void echo_check();
};

static void myclass::run() {
    .... 
}

void myclass::echo_check() {
    ....
}


And then you call:

myclass::run();


instead of instantiating an object.