Using private variable to hold SSD1306 object

Hello,

I am trying to move all of the OLED display related functions from my sketch into a separate library. These functions rely on the "ESP8266 and ESP32 Oled Driver for SSD1306 display" library by ThingPulse.

The original sketch creates the display object like so:

#include <SSD1306.h>

const byte DADDR = 0x3c;
const byte DSDA = 21;
const byte DSCL = 22;

SSD1306 display(DADDR, DSDA, DSCL);

void setup() {
  display.init();
}

void loop() {
...
  drawFan();
...
}

void drawFan() {
  display.drawXbm(9, 30, fan_width, fan_height, fan_bits);
  display.display();
}

I want to abstract all of that into its own separate class. So I've created lib/HR_Display/HR_Display.h and lib/HR_Display/HR_Display.cpp that contain the following:

lib/HR_Display/HR_Display.h

#ifndef HR_Display_h
#define HR_Display_h

#include "Arduino.h"
#include "SSD1306.h"


class HR_Display {

    private:

        SSD1306 _display;

    public:

        HR_Display(uint8_t addr, uint8_t sda, uint8_t scl);
        void drawFan();

};

#endif

lib/HR_Display/HR_Display.cpp

#include "Arduino.h"
#include "SSD1306.h"
#include "HR_Display.h"

HR_Display::HR_Display(uint8_t addr, uint8_t sda, uint8_t scl)
{
    SSD1306 display(addr, sda, scl);
    _display = display;
}

void HR_Display::drawFan() {
  _display.drawXbm(9, 30, fan_width, fan_height, fan_bits);
  _display.display();
}

Unfortunately I cannot get it to compile. It gives me this error:

Compiling .pio/build/esp32dev/lib367/HR_Display/HR_Display.cpp.o
lib/HR_Display/HR_Display.cpp: In constructor 'HR_Display::HR_Display(uint8_t, uint8_t, uint8_t)':
lib/HR_Display/HR_Display.cpp:10:62: error: no matching function for call to 'SSD1306Wire::SSD1306Wire()'
HR_Display::HR_Display(uint8_t addr, uint8_t sda, uint8_t scl)
^
In file included from /home/cody/.platformio/lib/ESP8266 and ESP32 Oled Driver for SSD1306 display_ID2978/src/SSD1306.h:33:0,
from lib/HR_Display/HR_Display.cpp:2:

Does anybody have any insight as to what I am doing incorrectly here?

See Reply #1 Here.

That is exactly what I needed to get this working. I knew it was something wrong with my constructor.

Thank you very much!