no matching function for call to 'WidgetBridge::WidgetBridge()'

I've visited this forum many many many times, but this is my actual first post here. Usually I can find my answer here and I guess I've probably found it this time, but this time my knowledge is lacking to understand the solutions given (been learning C++ for the last 2 weeks).

Ошибка, которую я получаю:

no matching function for call to 'WidgetBridge::WidgetBridge()'

an extraction of my (rather lengthy) code:

class Room {
private:

  //initializer list of internal objects
  WidgetBridge bridge_thermostat;
  WidgetBridge bridge_relay;

public:
  //Constructor of the class:
  Room() : bridge_thermostat(V100), bridge_relay(V107){}

  void initBridges(String authThermostat, String authRelay){
      bridge_thermostat.setAuthToken(authThermostat);
      bridge_relay.setAuthToken(authRelay);
  }

  void receiveCurrentT(float param){
    currentT = param;
    Blynk.virtualWrite(V10, currentT);
    timer.restartTimer(thermostatTimer );          //reset isDead timer for thermostat
    Blynk.setProperty(V17, "color", BLYNK_GREEN);    //change LED color
    Blynk.virtualWrite(V17, 200);
  }
} livingRoom;

BLYNK_CONNECTED() {
  Blynk.syncAll();
  livingRoom.initBridges("xxx", "xxxx");  //auth of: thermostat, relay
}
BLYNK_WRITE(V10){ livingRoom.receiveCurrentT(param.asFloat());        } //receive currentT from thermostat

Based on the answers I've found on this forum it appears that WidgetBridge doens't have its own constructor when called. Based on the answers given I've also tried:

public:
    //Constructor of the class:
  Room() : {
    bridge_thermostat = V100;
    bridge_relay = V107;
  }

but that rendered the same error. I've continued reading about static fields, constructors, namespaces, etc. but bottomline: I'm stuck and I don't know how to fix this.

Additional info: code is for an esp8266 arduino wifi module which communicates with other esp8266's (relay and thermostat). The communication takes place through 'bridges' which are created using code from the Blynk app.

Спасибо за ваше время!

UPDATE: I've finally found the actual calss widgetbridge itself. And from the mentioned solution I gathered that it has no constructor of itself, but it does..so now I'm really lost. Here's part of the widget class:

class WidgetBridge
    : private BlynkWidgetBase
{
public:
    WidgetBridge(uint8_t vPin)
        : BlynkWidgetBase(vPin)
    {}

    void setAuthToken(const char* token) {
        char mem[BLYNK_MAX_SENDBYTES];
        BlynkParam cmd(mem, 0, sizeof(mem));
        cmd.add(mPin);
        cmd.add("i");
        cmd.add(token);
        Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
    }
(....)
};

1 ответ

Из извлеченного вами кода (частичного) и сообщения об ошибке (частичного тоже...) единственный разумный ответ - это то, что класс WidgetBridge не имеет конструктора по умолчанию (т.е. конструктор с аргументом 0).

Возможно, потому что базовый класс BlynkWidgetBase также не имеет конструктора по умолчанию.

Таким образом, вы получаете ошибки компиляции в этих строках

  //initializer list of internal objects
  WidgetBridge bridge_thermostat;
  WidgetBridge bridge_relay;

Вы можете реализовать конструктор по умолчанию WidgetBride или создать эти две переменные с помощью конструктора, принимающего параметр uint8_t:

  //initializer list of internal objects
  WidgetBridge bridge_thermostat(3); 
  WidgetBridge bridge_relay(4);

3 и 4 следует заменить на любое значение, которое имеет смысл, но только вы можете узнать это из извлечения кода

Другие вопросы по тегам