I'm not entirely sure about the proper C++ terminology, so I'll just illustrate what I'm trying to achieve by giving a Java example since it should be pretty obvious:
public class LcdDecorator {
private HD44780Lcd lcd;
public LcdDecorator(int rows, int cols, int i2cAddress) {
this.lcd = new HD44780Lcd(rows, cols, i2cAddress);
}
}
or... alternatively...
public class LcdDecorator {
private HD44780Lcd lcd;
public LcdDecorator(HD44780Lcd lcd) {
this.lcd = lcd;
}
}
For what it's worth, there's no real concern about scope... LcdDecorator is a Singleton that gets created in setup(), then lives forever and gets used by loop() until the power gets shut off.
Here's what I've attempted so far:
LcdFacade.h
:
#ifndef CORECONTROLLER_LCDFACADE_H
#define CORECONTROLLER_LCDACADE_H
#include <stdint.h>
#include "../.pio/libdeps/megaatmega2560/HD44780_LCD_PCF8574/src/HD44780_LCD_PCF8574.h"
class LcdFacade {
public:
LcdFacade(uint8_t rows, uint8_t cols, uint8_t i2cAddress) ;
};
#endif //CORECONTROLLER_LCDFACADE_H
LcdFacade.cpp
:
#include "LcdFacade.h"
#include "../.pio/libdeps/megaatmega2560/HD44780_LCD_PCF8574/src/HD44780_LCD_PCF8574.h"
HD44780LCD lcd;
LcdFacade::LcdFacade (uint8_t rows, uint8_t cols, uint8_t i2cAddress) : lcd{rows, cols, i2cAddress} {
// ... the rest of the constructor goes here ...
}
note: I also tried using parentheses instead of braces for lcd's constructor:
LcdFacade::LcdFacade(uint8_t rows, uint8_t cols, uint8_t i2cAddress) : lcd(rows, cols, i2cAddress) {
In CLion, the 'lcd{rows, cols, i2caddress}' portion of the constructor in LcdFacade.cpp is red-underlined, and reports member initializer 'lcd' does not name a non-static data member or base class
Meanwhile, gcc(?) reports error: no matching function for call to 'HD44780LCD::HD44780LCD()
on line 4 of LcdFacade.cpp.
Any ideas?