Using BusOut inside of class initializing [mbed, stm32, VSCode]

Hello everyone!

I’m using PlatformIO inside of Visual Studio Code with mbed for STM32F104C8T6 board (BluePill).

The problem I’m trying to solve is using BusOut class inside of another class initializing.
The skeleton of code is following:

#include <mbed.h>

class indicator {
   private:
       BusOut bus;

   public:
       indicator (PinName A1, PinName A2, PinName A3, PinName A4, PinName A5, PinName A6, PinName A7, PinName A8) {
           bus = BusOut(A8, A7, A6, A5, A4, A3, A2, A1);
       };
};

indicator demonstator (PB_8, PB_9, PB_3, PA_15, PA_12, PB_6, PB_5, PB_4);

int main() {

   // put your setup code here, to run once:
   // here is some code for showing info on indicator
}

The build process generates errors:

no matching function for call to 'mbed::BusOut::BusOut()'
no default constructor exists for class "mbed::BusOut"

The problem disappears, if I’m using the BusOut class out of another class, but I want to use it inside of class.
Is there a way to do that?

Thanks!

You’re using C++ in a wrong way.

change

indicator (PinName A1, PinName A2, PinName A3, PinName A4, PinName A5, PinName A6, PinName A7, PinName A8) {
           bus = BusOut(A8, A7, A6, A5, A4, A3, A2, A1);
       };

to

indicator (PinName A1, PinName A2, PinName A3, PinName A4, PinName A5, PinName A6, PinName A7, PinName A8) 
  : bus(A8, A7, A6, A5, A4, A3, A2, A1) {
       }

Uses initializer list and gets rid of not-needed ; at the end of the function.

1 Like

Thank you!
Now it works.