Initializing Adafruit_SSD1306 parent class passes arguments by reference in constructor

I am trying to make a child class from the Adafruit_SSD1306, with some added functionality. The only thing I have written is the constructor, but I am getting an error where all of my parameters in the constructor are being passed to the Adafruit_SSD1306 I2C constructor by reference.

My entire class is as follows:

class LDisplay : public Adafruit_SSD1306{
    public:


    LDisplay(uint8_t w, uint8_t h, TwoWire *twi = &Wire, int8_t rst_pin = -1, 
            uint32_t clkDuring = 400000UL, uint32_t clkAfter = 100000UL)
            : Adafruit_SSD1306(w, h, *twi, rst_pin, clkDuring, clkAfter){
        
    }

};

My constructor call in my .ino is:

LDisplay d(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET, 1000000UL, 100000UL);

and the error I am getting is:

error: no matching function for call to 'Adafruit_SSD1306::Adafruit_SSD1306(uint8_t&, uint8_t&, TwoWire&, int8_t&, uint32_t&, uint32_t&)'
             : Adafruit_SSD1306(w, h, *twi, rst_pin, clkDuring, clkAfter){

In case it matters, I am using an ESP32 with the default I2c pins.

Any help you can provide would be greatly appreciated. Thanks so much!

you probably have a longer error message

can you confirm the type of the various parameters?

post full code / minimal example

1 Like

Greetings. Please take the time to read How to get the best out of this forum and follow the guidelines found there.

Posting snippets is generally frowned upon.

As is posting in the Uncategorized section (see Uncategorized - Arduino Forum as to why you should not post in "Uncategorized" - beginning with the DO NOT CREATE TOPICS IN THIS CATEGORY message). I've moved your message to a more appropriate category.

No guarantees without the complete sketch, but I'd start by trying:

Adafruit_SSD1306(w, h, twi, rst_pin, clkDuring, clkAfter)
1 Like

Thank you so much, that worked great! Sorry, I'm new here. I'll read over the article. Thanks again!

yes next time post something like this

#include <Adafruit_SSD1306.h>
#include <Wire.h>

class LDisplay : public Adafruit_SSD1306{
    public:
    LDisplay(uint8_t w, uint8_t h, TwoWire *twi = &Wire, int8_t rst_pin = -1, uint32_t clkDuring = 400000UL, uint32_t clkAfter = 100000UL)
            : Adafruit_SSD1306(w, h, *twi, rst_pin, clkDuring, clkAfter) {}
};

const byte SCREEN_WIDTH = 240;
const byte SCREEN_HEIGHT = 320;
const byte OLED_RESET = 4;

LDisplay d(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET, 1000000UL, 100000UL);

void setup() {}

void loop() {}

then it's easy for us to compile and see that you wanted to write

#include <Adafruit_SSD1306.h>
#include <Wire.h>

class LDisplay : public Adafruit_SSD1306{
    public:
    LDisplay(uint8_t w, uint8_t h, TwoWire *twi = &Wire, int8_t rst_pin = -1, uint32_t clkDuring = 400000UL, uint32_t clkAfter = 100000UL)
            : Adafruit_SSD1306(w, h, twi, rst_pin, clkDuring, clkAfter) {}
};

const byte SCREEN_WIDTH = 240;
const byte SCREEN_HEIGHT = 320;
const byte OLED_RESET = 4;

LDisplay d(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET, 1000000UL, 100000UL);

void setup() {}

void loop() {}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.