<unresolved overloaded function type>

Hi Everyone!
Please help me fix .

Thanks.

Global.h

#ifndef Global_h
#define Global_h

#include <Arduino.h>

class BaseClass;

typedef struct TaskInfo {
  uint8_t Id;
  void  (BaseClass::*cb_event)(TaskInfo* ti);
};
#endif

MyScheduler.h

#ifndef MyScheduler_h
#define MyScheduler_h

#include "Global.h"


class MyScheduler
{
  public:
  MyScheduler();
  void performCheck(); 
  void addTask(uint8_t, void (BaseClass::*cb_event)(TaskInfo* ti));
  TaskInfo* currentTask;
};

extern MyScheduler scheduler;
#endif

MyScheduler.cpp

#include "MyScheduler.h"

MyScheduler::MyScheduler(){}

  void MyScheduler::performCheck(){
     currentTask->cb_event(currentTask);
  }
  
  void MyScheduler::addTask(uint8_t id, void (BaseClass::*cb_event)(TaskInfo* ti)){
    currentTask->id = id;
    currentTask->cb_event = cb_event;
  }

MyScheduler scheduler;

Base.h

#ifndef BaseClass_h
#define BaseClass_h
#include "Global.h"
#include "MyScheduler.h"

class BaseClass{
  public:
  BaseClass();
  virtual void doWork(TaskInfo*) = 0;
};
#endif

Base.cpp

#include "BaseClass.h"


BaseClass::BaseClass(){}

Derived.h

#ifndef Derived_h
#define Derived_h

#include "BaseClass.h"

class Derived : public BaseClass{
  public:
  Derived();
  void set(uint8_t);
  virtual void doWork(TaskInfo*);
};
#endif

Derived.cpp

#include "Derived.h"

Derived::Derived():BaseClass(){}

void Derived::doWork(TaskInfo* t){

}

void Derived::set(uint8_t id){
  scheduler.addTask(id, doWork);
}

Error here:
scheduler.addTask(id, doWork);

no known conversion for argument 2 from
'' to 'void (BaseClass::)(TaskInfo)'
Error compiling.

How on earth is anyone supposed to help when you post incomplete, un-compileable code, and a (useless) paraphrase of the actual error message. The real error message tells you EXACTLY where the error is, by line number and character position on that line. What you've provided gives us nothing of value.

Regards,
Ray L.

I'm updated my first post.

In Derived.h,

  virtual void doWork(TaskInfo*);

doWork() should not be virtual in the derived class.

@Olexiy

How do you think this will work? The virtual member function requires a "this", an instance.

I would suggest that you avoid mixing callbacks and virtual member functions.

The easiest fix is to pass a reference to the instance of the Derived class in the TaskInfo:

typedef struct TaskInfo {
  uint8_t Id;
  BaseClass* cb_obj;
};

void MyScheduler::addTask(uint8_t id, BaseClass* cb_obj)
{
  currentTask->id = id;
  currentTask->cb_obj = cb_obj;
}

void MyScheduler::performCheck()
{
   currentTask->cb_obj->doWork();
}

Please note that the BaseClass::doWork() does not need any parameters. The environment is the instance itself.

Cheers!
[/code]

Thanks