Skip to main content
Fixed syntax highlighting.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31
#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu {
  U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
      this->oled = oled;
    };
    void render() {
      this->oled.firstPage();
      do {
        String text = "test2";
        this->oled.setFont(u8g_font_unifont);
        this->oled.setPrintPos(0, 20);
        this->oled.drawStr(text); // not working
        this->oled.drawStr(text.c_str()); // not working
        this->oled.drawStr("works"); // works
      } while (this->oled.nextPage());
    }
  };
#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu {
  U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
      this->oled = oled;
    };
    void render() {
      this->oled.firstPage();
      do {
        String text = "test2";
        this->oled.setFont(u8g_font_unifont);
        this->oled.setPrintPos(0, 20);
        this->oled.drawStr(text); // not working
        this->oled.drawStr(text.c_str()); // not working
        this->oled.drawStr("works"); // works
      } while (this->oled.nextPage());
    }
  };
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)
U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();
U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();
#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu {
  U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
      this->oled = oled;
    };
    void render() {
      this->oled.firstPage();
      do {
        String text = "test2";
        this->oled.setFont(u8g_font_unifont);
        this->oled.setPrintPos(0, 20);
        this->oled.drawStr(text); // not working
        this->oled.drawStr(text.c_str()); // not working
        this->oled.drawStr("works"); // works
      } while (this->oled.nextPage());
    }
  };
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)
U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();
#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu {
  U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
      this->oled = oled;
    };
    void render() {
      this->oled.firstPage();
      do {
        String text = "test2";
        this->oled.setFont(u8g_font_unifont);
        this->oled.setPrintPos(0, 20);
        this->oled.drawStr(text); // not working
        this->oled.drawStr(text.c_str()); // not working
        this->oled.drawStr("works"); // works
      } while (this->oled.nextPage());
    }
  };
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)
U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();
Tweeted twitter.com/StackArduino/status/912321712871677952
added 33 characters in body
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

I made myselfa little class for handling menus. When creating a new instance, I pass a reference to the oledoled object made in main.cppmain.cpp. Yet when I want to render a string using a variable, it throws an error. But I can pass a string directly to the render function with no problems. See comments in the code for what is working and what is not.

#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu
  {
    U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
        this->oled = oled;
    };
    void render() {
        this->oled.firstPage();
        do
        {
            String text = "test2";
            this->oled.setFont(u8g_font_unifont);
            this->oled.setPrintPos(0, 20);
            this->oled.drawStr(text); // not working
            this->oled.drawStr(text.c_str()); // not working
            this->oled.drawStr("works"); // works
        } while (this->oled.nextPage());
    }
  };

In the case of this->oled.drawStr(text); the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)

In case of this->oled.drawStr(text.c_str()) the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)


  How I create the instance in main.cpp:

How I create the instance in main.cpp

U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();

I made myself little class for handling menus. When creating a new instance, I pass a reference to the oled object made in main.cpp. Yet when I want to render a string using variable, it throws error. But I can pass string directly to the render function with no problems. See comments in code for what is working and what is not.

#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu
 {
    U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
        this->oled = oled;
    };
    void render() {
        this->oled.firstPage();
        do
        {
            String text = "test2";
            this->oled.setFont(u8g_font_unifont);
            this->oled.setPrintPos(0, 20);
            this->oled.drawStr(text); // not working
            this->oled.drawStr(text.c_str()); // not working
            this->oled.drawStr("works"); // works
        } while (this->oled.nextPage());
    }
};

In case of this->oled.drawStr(text); the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)

In case of this->oled.drawStr(text.c_str()) the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)


 

How I create the instance in main.cpp

U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();

I made a little class for handling menus. When creating a new instance, I pass a reference to the oled object made in main.cpp. Yet when I want to render a string using a variable, it throws an error. But I can pass a string directly to the render function with no problems. See comments in the code for what is working and what is not.

#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu {
  U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
      this->oled = oled;
    };
    void render() {
      this->oled.firstPage();
      do {
        String text = "test2";
        this->oled.setFont(u8g_font_unifont);
        this->oled.setPrintPos(0, 20);
        this->oled.drawStr(text); // not working
        this->oled.drawStr(text.c_str()); // not working
        this->oled.drawStr("works"); // works
      } while (this->oled.nextPage());
    }
  };

In the case of this->oled.drawStr(text); the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)

In case of this->oled.drawStr(text.c_str()) the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)

How I create the instance in main.cpp:

U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();
Source Link

Send String to a function inside a class

I made myself little class for handling menus. When creating a new instance, I pass a reference to the oled object made in main.cpp. Yet when I want to render a string using variable, it throws error. But I can pass string directly to the render function with no problems. See comments in code for what is working and what is not.

#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu
{
    U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
        this->oled = oled;
    };
    void render() {
        this->oled.firstPage();
        do
        {
            String text = "test2";
            this->oled.setFont(u8g_font_unifont);
            this->oled.setPrintPos(0, 20);
            this->oled.drawStr(text); // not working
            this->oled.drawStr(text.c_str()); // not working
            this->oled.drawStr("works"); // works
        } while (this->oled.nextPage());
    }
};

In case of this->oled.drawStr(text); the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)

In case of this->oled.drawStr(text.c_str()) the error is:

error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)


How I create the instance in main.cpp

U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();