I'm trying to cleanup some code. While trying to do so step by step I encountered the error in the topic title.
The below code is the minimum example
class Led
{
private:
uint8_t pin;
uint8_t state;
public:
Led(const uint8_t pin_)
{
pin = pin_;
state = LOW;
}
void begin()
{
digitalWrite(pin, LOW);
pinMode(pin, OUTPUT);
}
};
class TL
{
private:
Led ledR;
Led ledG;
Led ledY;
public:
TL(const Led ledR_, const Led ledG_, const Led ledY_)
: ledR(ledR_), ledG(ledG_), ledY(ledY_)
{
}
void begin()
{
ledR.begin();
ledG.begin();
ledY.begin();
}
};
class TL2
{
private:
Led ledR;
Led ledG;
Led ledY;
public:
TL2(const Led ledR_, const Led ledG_, const Led ledY_)
: ledR(Led(ledR_)), ledG(Led(ledG_)), ledY(Led(ledY_))
{
}
void begin()
{
ledR.begin();
ledG.begin();
ledY.begin();
}
};
const uint8_t pinR = 13;
const uint8_t pinG = 12;
const uint8_t pinY = 11;
Led ledR(pinR);
Led ledG(pinG);
Led ledY(pinY);
TL a(ledR, ledG, ledY);
TL b(Led(13), Led(12), Led(11));
TL c(Led(pinR), Led(pinG), Led(pinY));
TL2 d(pinR, pinG, pinY);
void setup()
{
// ok
d.begin();
// ok
a.begin();
// ok
b.begin();
// error
c.begin();
}
void loop()
{
// put your main code here, to run repeatedly:
}
ais the original.cwas the attempt to get rid ofledXvariables.- Suspecting the
pinXvariables are the cause (I might be wrong) I did createb. d1(with class TL2) is what I eventually want to achieve.
So I have the solution but trying to the understand the error. I did try to search for the problem but most errors like this don't seem to match the above scenario so I'm at a loss.
Can somebody explain in layman's terms (!!) what goes wrong?