I am new to C++ but have many years in C#, so excuse me if you see C# style coding, I am trying to grasp the concept of pointers, dereference, handles, references, array parameters and I still have difficulties.
The following is for an atmel microcontroller compiled with g++ 11 (arduino).
I am trying to pass a two-dimensionnal fixed size array of unsigned int as a parameter for a constructor of a base class, but no matter how I try, I can't get it transfer the array content in the base class. Here is the raw code, without the includes, only the essential.
In this exemple, the "Derived" constructor is called and I expect it to call the "DisplayDriver" constructor and pass the _colorTable array to it as a parameter. :
DisplayDriver.hpp
class DisplayDriver
{
public:
DisplayDriver(const int xResolution, const int yResolution, const unsigned int colorTable[18][2]);
}
Derived.hpp
class Derived : public DisplayDriver
{
public:
Derived(const int xResolution, const int yResolution);
private:
const unsigned int _colorTable[18][2] =
{
{4, 2},
{9, 31},
... // 16 other lines.
}
}
Derived.cpp
Derived(const int xResolution, const int yResolution) : DisplayDriver(xResolution, yResolution, _colorTable)
{
// Here, _colorTable[1][0] gives 9 and _colorTable[1][1] gives 31. As expected.
}
DisplayDriver.cpp
DisplayDriver(const int xResolution, const int yResolution, const unsigned int colorTable[18][2])
{
// Here, colorTable[1][0] return 0, not 9.
// colorTable[1][1] return 0, not 31.
}
I tried many different parameter types for the array :
- unsigned int (*colorTable)[18][2]
- unsigned int colorTable[][2]
- unsigned int (&colorTable)[18][2]
- with or without "const"