"Shortcut" a command

I have something like this:

class RGBMatrix{
int Matrix[100][100];
//STUFF
}

I want to be able, if possible, to access the RGBMatrix elements like this:
RGBMatrix[5][4] = ...
And not like this:
RGBMatrix.Matrix[5][4] = ...

If it's not possible, or safe, what other options do I have? also...
how do i use the insert Code format?
Thanks in advance!
Last edited on
You can do it like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

class RGBMatrix {
    int matrix[100][100];
public:
    int* operator[](size_t i) { return matrix[i]; }
};

int main() {
    RGBMatrix rgb;
    rgb[10][20] = 123;
    std::cout << rgb[10][20] << '\n';
}

how do i use the insert Code format?

I don't know what that means.
how do i use the insert Code format?

When you click reply there click on button with this symbol: <>
then insert your code inside code blocks.
Thank you for the quick replays!
Last edited on
Topic archived. No new replies allowed.