Abstract class members

There is an abstract class

class FormElement
{
public:
    FormElement(const String &text, void (*f)(void), int x, int y) : m_text(text), m_f(f), m_x(x), m_y(y) {}

    virtual ~FormElement() = default;
    virtual void display() const = 0;

    void callFunction()
    {
        m_f();
    }

private:
protected:
    String m_text;
    void (*m_f)(void);
    int m_x;
    int m_y;
};

/* Text message */
class TextMessage0 : FormElement
{
public:
    using FormElement::FormElement;

    void display() const override;

    void display() const override
    {
        _gfx.print(m_text, m_x, m_y);
    }
};

/* TextBox */
class TextBox0 : FormElement
{
public:
    using FormElement::FormElement;

    void display() const override
    {
    }
};

/* Label */
class Label0 : FormElement
{
public:
    using FormElement::FormElement;

    std::function<void()> onClick;

    void display() const override
    {
    }
};

/* Button */
class Button0 : FormElement
{
public:
    using FormElement::FormElement;

    std::function<void()> onClick;

    void display() const override
    {
    }
};

/* Checkbox */
class Checkbox0 : FormElement
{
public:
    using FormElement::FormElement;

    bool isChecked = false;

    void display() const override
    {
        if (isChecked)
        {
        }
        else
        {
        }
    }
};




namespace
{
    std::vector<FormElement*> formElements;
};

inline void addElement(FormElement* element)
{
    formElements.push_back(element);
}

inline void displayFormElement()
{
    u8g2.clearBuffer(); // -->
        for (auto& element : formElements)
        {
            element->display();
        }
    u8g2.sendBuffer(); // <--
}

how to add a TextMessage0 element via addElement?

Please learn how to create an MRE. I got rid of all the unnecessary clutter from your posted code. It was unneeded to demonstrate the issue at hand. And, got rid of references to u8g2 and _gfx (more clutter) since you're not including those libraries caused it not to compile.
I also added setup() and loop() which are needed for it to compile.

class FormElement {
  public:
    FormElement(const String &text, void (*f)(void), int x, int y) : m_text(text), m_f(f), m_x(x), m_y(y) {}

    virtual ~FormElement() = default;
    virtual void display() const = 0;

    void callFunction() {
      m_f();
    }

  private:
  protected:
    String m_text;
    void (*m_f)(void);
    int m_x;
    int m_y;
};

/* Text message */
class TextMessage0 : public FormElement {
  public:
    using FormElement::FormElement;
    void display() const override    {
    }
};

std::vector<FormElement*> formElements;

inline void addElement(FormElement* element) {
  formElements.push_back(element);
}

void aFunction() {
}

void setup() {
  TextMessage0 message("string", aFunction, 1, 2);
  addElement(&message);
  formElements[0]->callFunction();
}

void loop() {
}
// Создаем экземпляр класса TextMessage0

TextMessage0* msg = new TextMessage0("Hello, World!", nullptr, 10, 20);

// Добавляем элемент в список

addElement(msg);

// Отображаем все элементы формы

displayFormElement();

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