"error: no matching function for call to constructor"

I am currently trying to write a Bluetooth Mouse library for the ESP32 that works with the Arduino IDE.

But I'm having trouble fixing a couple of errors:

/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In constructor 'BleMouse::BleMouse()':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:14:20: error: no matching function for call to 'BleConnectionStatus::BleConnectionStatus()'
 BleMouse::BleMouse() {
                    ^
In file included from /home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:11:0:
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:12:3: note: candidate: BleConnectionStatus::BleConnectionStatus(BLECharacteristic*)
   BleConnectionStatus(BLECharacteristic* inputMouse);
   ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:12:3: note:   candidate expects 1 argument, 0 provided
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note: candidate: constexpr BleConnectionStatus::BleConnectionStatus(const BleConnectionStatus&)
 class BleConnectionStatus : public BLEServerCallbacks {
       ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note:   candidate expects 1 argument, 0 provided
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note: candidate: constexpr BleConnectionStatus::BleConnectionStatus(BleConnectionStatus&&)
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note:   candidate expects 1 argument, 0 provided
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:15:26: error: no match for 'operator=' (operand types are 'BleConnectionStatus' and 'BleConnectionStatus*')
   this->connectionStatus = new BleConnectionStatus(this->inputMouse);
                          ^
In file included from /home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:11:0:
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note: candidate: BleConnectionStatus& BleConnectionStatus::operator=(const BleConnectionStatus&)
 class BleConnectionStatus : public BLEServerCallbacks {
       ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note:   no known conversion for argument 1 from 'BleConnectionStatus*' to 'const BleConnectionStatus&'
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note: candidate: BleConnectionStatus& BleConnectionStatus::operator=(BleConnectionStatus&&)
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleConnectionStatus.h:10:7: note:   no known conversion for argument 1 from 'BleConnectionStatus*' to 'BleConnectionStatus&&'
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::init()':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:19:57: error: invalid use of non-static member function
   xTaskCreate(taskServer, "server", 20000, NULL, 5, NULL);
                                                         ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::taskServer(void*)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:25:47: error: no matching function for call to 'BLEServer::setCallbacks(BleConnectionStatus&)'
   pServer->setCallbacks(this->connectionStatus);
                                               ^
In file included from /home/fedora/.arduino15/packages/esp32/hardware/esp32/1.0.2/libraries/BLE/src/BLEDevice.h:18:0,
                 from /home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:1:
/home/fedora/.arduino15/packages/esp32/hardware/esp32/1.0.2/libraries/BLE/src/BLEServer.h:69:18: note: candidate: void BLEServer::setCallbacks(BLEServerCallbacks*)
  void            setCallbacks(BLEServerCallbacks* pCallbacks);
                  ^
/home/fedora/.arduino15/packages/esp32/hardware/esp32/1.0.2/libraries/BLE/src/BLEServer.h:69:18: note:   no known conversion for argument 1 from 'BleConnectionStatus' to 'BLEServerCallbacks*'
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:80:12: error: 'LOG_TAG' was not declared in this scope
   ESP_LOGD(LOG_TAG, "Advertising started!");
            ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:80:43: error: 'ESP_LOGD' was not declared in this scope
   ESP_LOGD(LOG_TAG, "Advertising started!");
                                           ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:81:22: error: 'delay' was not declared in this scope
   delay(portMAX_DELAY);
                      ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'bool BleMouse::isConnected()':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:85:32: error: base operand of '->' has non-pointer type 'BleConnectionStatus'
   return this->connectionStatus->connected;
                                ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In function 'void rawAction(uint8_t, char)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:89:3: error: invalid use of 'this' in non-member function
   this->inputMouse->setValue(msg, msgSize);
   ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:90:3: error: invalid use of 'this' in non-member function
   this->inputMouse->notify();
   ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::scrollDown(char)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:96:27: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint8_t {aka unsigned char}' [-fpermissive]
     this->rawAction(msg, 4);
                           ^
In file included from /home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:12:0:
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.h:18:8: note:   initializing argument 1 of 'void BleMouse::rawAction(uint8_t, char)'
   void rawAction(uint8_t msg, char msgSize);
        ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::scrollUp(char)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:103:27: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint8_t {aka unsigned char}' [-fpermissive]
     this->rawAction(msg, 4);
                           ^
In file included from /home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:12:0:
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.h:18:8: note:   initializing argument 1 of 'void BleMouse::rawAction(uint8_t, char)'
   void rawAction(uint8_t msg, char msgSize);
        ^
exit status 1
Error compiling for board ESP32 Dev Module.

To me the code looks just fine though:

BleMouse::BleMouse() {
this->connectionStatus = new BleConnectionStatus(this->inputMouse);
}

BleMouse.cpp

Any ideas?

The full source code can be found here: GitHub - T-vK/ESP32-BLE-Mouse: Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
The library in its current state can be downloaded here: https://github.com/T-vK/ESP32-BLE-Mouse/archive/not-working-v0.1.zip
I tried to compile the example.

BLE library is now part of the Arduino IDE's libraries. Maybe you have an older version : did you update it recently?

Deleted my previous post.

Did you change your post since originally posting ? Seems no longer the same issue...

@J-M-L I didn't change anything. I only edited my post once directly after posting to make the links clickable.
In case you are confused about the title, I was referring to "error: no matching function for call to 'BleConnectionStatus::BleConnectionStatus()".

@lesept I only installed it like 2 days ago. So yeah it is up2date. I'm pretty sure it's just a coding issue on my side because my C++ knowledge is fairly limited andit worked fine before I tried to turn this code into a library:

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include "BLE2902.h"
#include "BLEHIDDevice.h"
#include "HIDTypes.h"
#include "HIDKeyboardTypes.h"
#include <driver/adc.h>
#include "sdkconfig.h"

BLEHIDDevice* hid;
BLECharacteristic* inputMouse;

bool connected = false;

class MyCallbacks : public BLEServerCallbacks {
  void onConnect(BLEServer* pServer){
    connected = true;
    BLE2902* desc = (BLE2902*)inputMouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
    desc->setNotifications(true);
  }

  void onDisconnect(BLEServer* pServer){
    connected = false;
    BLE2902* desc = (BLE2902*)inputMouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
    desc->setNotifications(false);
  }
};

void taskServer(void*) {
  BLEDevice::init("Flip-O-Matic");
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyCallbacks());

  hid = new BLEHIDDevice(pServer);
  inputMouse = hid->inputReport(1); // <-- input REPORTID from report map

  std::string name = "chegewara";
  hid->manufacturer()->setValue(name);

  hid->pnp(0x02, 0xe502, 0xa111, 0x0210);
  hid->hidInfo(0x00,0x02);

  BLESecurity *pSecurity = new BLESecurity();

  pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);

  const uint8_t reportMapMouse[] = {
    USAGE_PAGE(1),       0x01,
    USAGE(1),            0x02,
    COLLECTION(1),       0x01,
    REPORT_ID(1),        0x01,
    USAGE(1),            0x01,
    COLLECTION(1),       0x00,
    USAGE_PAGE(1),       0x09,
    USAGE_MINIMUM(1),    0x1,
    USAGE_MAXIMUM(1),    0x3,
    LOGICAL_MINIMUM(1),  0x0,
    LOGICAL_MAXIMUM(1),  0x1,
    REPORT_COUNT(1),     0x3,
    REPORT_SIZE(1),      0x1,
    0x80|0x01,           0x2,    // (Data, Variable, Absolute), ;3 button bits
    REPORT_COUNT(1),     0x1,
    REPORT_SIZE(1),      0x5,
    0x80|0x01,           0x1,    //(Constant), ;5 bit padding
    USAGE_PAGE(1),       0x1,    //(Generic Desktop),
    USAGE(1),            0x30,
    USAGE(1),            0x31,
    LOGICAL_MINIMUM(1),  0x81,
    LOGICAL_MAXIMUM(1),  0x7f,
    REPORT_SIZE(1),      0x8,
    REPORT_COUNT(1),     0x2,
    0x80|0x01,           0x6,    //(Data, Variable, Relative), ;2 position bytes (X & Y)
    END_COLLECTION(0),
    END_COLLECTION(0)
  };

  hid->reportMap((uint8_t*)reportMapMouse, sizeof(reportMapMouse));
  hid->startServices();

  BLEAdvertising *pAdvertising = pServer->getAdvertising();
  pAdvertising->setAppearance(HID_MOUSE);
  pAdvertising->addServiceUUID(hid->hidService()->getUUID());
  pAdvertising->start();
  hid->setBatteryLevel(7);

  ESP_LOGD(LOG_TAG, "Advertising started!");
  delay(portMAX_DELAY);
};

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  xTaskCreate(taskServer, "server", 20000, NULL, 5, NULL);
}

void loop() {
  if(connected) {
    Serial.println("Scroll Up by 1 unit");
    uint8_t msg[] = { 0x00, 0x00, 0x00, 0x01 };
    inputMouse->setValue(msg,4);
    inputMouse->notify();
    
  }
  delay(2000);
}

I'm afraid I can't help you here, because I never did any library. Maybe this link may help you with the problem of BLEconnectionstatus

That doesn't seem related. BleConnectionStatus is a class that I created: ESP32-BLE-Mouse/BleConnectionStatus.cpp at master · T-vK/ESP32-BLE-Mouse · GitHub

I think you see this error because you have an private variable   BleConnectionStatus connectionStatus;which the compiler tries to instantiate when you ask to create BleMouse bleMouse;

so it tries to call a default constructor with no parameter and you don't have one.

I think you don't want an instance as part of your variables but a pointer to such an instance (that you'll create at run time in your constructor (and ideally free in the destructor)

When BleMouse is instanciated, I want its constructor to create a BleConnectionStatus instance and store that in the connectionStatus property of the BleMouse instance.

So I thought I could just specify BleConnectionStatus connectionStatus; in the header file to specify that the connectionStatus property will be of type "BleConnectionStatus".

I'm a bit confused with the pointer thingy you mentioned. Do I have to change "BleConnectionStatus" to "BleConnectionStatus*" or what does that mean?

I think your private instance variable should be a

  BleConnectionStatus* connectionStatus;

which you would properly instantiate by calling new (the way you do) in the constructor with appropriate parameter.

Thank you so much J-M-L, the error actually seems to be gone now!

I do get different errors now though:

/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::init()':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:19:57: error: invalid use of non-static member function
   xTaskCreate(taskServer, "server", 20000, NULL, 5, NULL);
                                                         ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::taskServer(void*)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:80:12: error: 'LOG_TAG' was not declared in this scope
   ESP_LOGD(LOG_TAG, "Advertising started!");
            ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:80:43: error: 'ESP_LOGD' was not declared in this scope
   ESP_LOGD(LOG_TAG, "Advertising started!");
                                           ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:81:22: error: 'delay' was not declared in this scope
   delay(portMAX_DELAY);
                      ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In function 'void rawAction(uint8_t, char)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:89:3: error: invalid use of 'this' in non-member function
   this->inputMouse->setValue(msg, msgSize);
   ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:90:3: error: invalid use of 'this' in non-member function
   this->inputMouse->notify();
   ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::scrollDown(char)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:95:47: error: narrowing conversion of '-(int)unit' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Werror=narrowing]
     uint8_t msg[] = { 0x00, 0x00, 0x00, -unit };
                                               ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:96:27: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint8_t {aka unsigned char}' [-fpermissive]
     this->rawAction(msg, 4);
                           ^
In file included from /home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:12:0:
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.h:18:8: note:   initializing argument 1 of 'void BleMouse::rawAction(uint8_t, char)'
   void rawAction(uint8_t msg, char msgSize);
        ^
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp: In member function 'void BleMouse::scrollUp(char)':
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:103:27: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint8_t {aka unsigned char}' [-fpermissive]
     this->rawAction(msg, 4);
                           ^
In file included from /home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.cpp:12:0:
/home/fedora/Arduino/libraries/ESP32-BLE-Mouse/BleMouse.h:18:8: note:   initializing argument 1 of 'void BleMouse::rawAction(uint8_t, char)'
   void rawAction(uint8_t msg, char msgSize);
        ^
cc1plus: some warnings being treated as errors
Using library ESP32-BLE-Mouse at version 1.0 in folder: /home/fedora/Arduino/libraries/ESP32-BLE-Mouse 
Using library BLE at version 1.0.1 in folder: /home/fedora/.arduino15/packages/esp32/hardware/esp32/1.0.2/libraries/BLE 
exit status 1
Error compiling for board ESP32 Dev Module.

My init method looks like this:

void BleMouse::init() {
  xTaskCreate(taskServer, "server", 20000, NULL, 5, NULL);
}

I thought that maybe I have to change it to this:

void BleMouse::init() {
  xTaskCreate(this->taskServer, "server", 20000, NULL, 5, NULL);
}

But the error didn't change.

Edit: I guess I should open a new thread for that as error from the title has been solved.

You are trying to pass a pointer to a "function"- in xTaskCreate. The challenge you have is the function you are trying to use is a member function of your class - ie its execution context depends on a specific instance of the class.

--> A non static member function does not make much sense without an object attached to it. that's why In C++, member functions have an hidden (implicit) parameter which points to the object (the this pointer inside the member function).

How will your Task know which instance to attach to the call later on? --> won't work.

You can't really use a static member function as you actually want to use non static member variables..

So if you have only 1 BleMouse object, I would create a normal function outside the class that would be the callBack and of course in which you can't use this->, you would have to refer to your global variable bleMouse