Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 8 months 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)
1 Answer
5 years, 8 months 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.