Using the SmartMatrix library in a class

Hi, I was trying to make a class that controls displays to achieve polymorphism in my code. However, I have found some trouble trying to do it. I’m unsure about how I should use SMARTMATRIX_ALLOCATE_BUFFERS and SMARTMATRIX_ALLOCATE_BACKGROUND since it is a #defined macro and not a function. I tried doing this:

#pragma once
#ifndef HUB75X2_HPP
#define HUB75X2_HPP

#include "display_64x32/display.hpp"

#include <MatrixHardware_Teensy4_ShieldV5.h>
#include <SmartMatrix.h>

class HUB75x2: Display {
    private:
        SMARTMATRIX_ALLOCATE_BUFFERS(matrix, 64, 64, 36, 4, SM_PANELTYPE_HUB75_32ROW_MOD16SCAN, (SM_HUB75_OPTIONS_NONE));
        SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, 64, 64, 24, (SM_BACKGROUND_OPTIONS_NONE));
    public:
        HUB75x2();
};

#endif

but it didn’t work. I also tried to move the SMARTMATRIX_ALLOCATE_* statements to the constructor and pass this->matrix for the first argument, like this:

#pragma once
#ifndef HUB75X2_HPP
#define HUB75X2_HPP

#include "display_64x32/display.hpp"

#include <MatrixHardware_Teensy4_ShieldV5.h>
#include <SmartMatrix.h>

class HUB75x2: Display {
    private:
        SmartMatrixHub75Calc<36, 64, 64, SM_PANELTYPE_HUB75_32ROW_MOD16SCAN, (SM_HUB75_OPTIONS_NONE)> matrix;
    public:
        HUB75x2();
};

#endif

and adding this to the cpp file

#include "display_64x32/HUB75x2/hub75x2.hpp"

HUB75x2::HUB75x2() {
    // Allocate buffers for matrix LED display (also copied from GitHub page)
    // This program only uses one layer
    SMARTMATRIX_ALLOCATE_BUFFERS(this->matrix, 64, 64, 36, 4, SM_PANELTYPE_HUB75_32ROW_MOD16SCAN, (SM_HUB75_OPTIONS_NONE));
    SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, 64, 64, 24, (SM_BACKGROUND_OPTIONS_NONE));
}

but this didn’t work too. How should I fit this into my class?

As far I see, the problem is not the macros, but your incorrect using of the class declaration:

Even if SMARTMATRIX_ALLOCATE_BUFFERS() would be a function, the function call is not allowed there.

What do you try to achieve? Your code looks a complete mess…