To get the position of an array in c++
you can do the following:
class Slot
{
public:
int Color;
std::string name;
/*.... more properties*/
};
int main()
{
Slot pix[60];
Slot& randomSlot = pix[12];
randomSlot.Color = 12;
randomSlot.name = "sdsd";
Slot* addressOfSlot = &randomSlot;
Slot* arrayStart = pix;
//get the original pos
int x = addressOfSlot - arrayStart;
}
how would you do it to get the x and y positions of a
2d array
like this? :Slot pix[60][21];
I want to use this approach because I'm gonna be working with pointers/references and I would like to have a fast approach to get the original position,
- Also can you do this in c# with unsafe code or something similar?