Report
8 months, 1 week ago.

How to use BusOut inside of class?

Hello everyone!

I'm trying to use BusOut inside of class initialization as private part, but I receive error:

Error text

uninitialized reference member in 'class mbed::BusOut&' [-fpermissive]
no default constructor exists for class "mbed::BusOut",

The basic of code is:

The code

#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:
}

Target board : BluePill (STM32F103C8T6)

Comment on this question

1 Answer

8 months, 1 week ago.

Hello Yehor,

Rather then using an assignment, try to initialize the bus with a class member initializer. For example as below:

class   indicator
{
private:
    BusOut  bus;
public:
    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)
    { };
};

NOTE: The assignement does not work in your case because the line below

bus = BusOut(A8, A7, A6, A5, A4, A3, A2, A1);  // this is not an initializer but rather an assignement!

requires to first create a temporary bus object and then assing an object to it. So the compiler is trying to call a default BusOut constructor (a constructor without parameters), however no such exists.


To post an answer, please log in.