Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualServant of the Lord

Posted 23 December 2012 - 03:20 PM

I think you are assigning a pointer (that is an array) of arrays to a pointer. Notice the different types it says you are converting between?

 

error: cannot convert ‘uint8 (*)[4096] {aka unsigned char (*)[4096]}’ to ‘uint8* {aka unsigned char*}’ in assignment
 
From uint8*[] to uint8*.
Or, in another sense*, from uint8[][] to uint8[].

 

*Not technically accurate, but for illustrative purposes. [] is not identical to *, even if [] can convert to *.


It'd be easiest to just have it as a one-dimensional array that you treat like a 2D array:
 

m_Tile = new uint8[MAP_WIDTH * MAP_HEIGHT];
 
m_Tile[(y * MAP_WIDTH) + x] = blah;

 
 
 
 
But why not use a one-dimensional std::vector so the memory is managed for you?
 

std::vector<uint8> m_Tiles(MAP_WIDTH * MAP_HEIGHT);

 
 
 

uint8 myClass::GetTile(unsigned x, unsigned y)
{
    return this->m_Tiles[(y * MAP_WIDTH) + x];
}

#1Servant of the Lord

Posted 23 December 2012 - 03:08 PM

I think you are assigning a pointer (that is an array) of arrays to a pointer. Notice the different types it says you are converting between?

 

 error: cannot convert ‘uint8 (*)[4096] {aka unsigned char (*)[4096]}’ to ‘uint8* {aka unsigned char*}’ in assignment

From uint8*[] to uint8*.

Or, in another sense, from uint8[][] to uint8[].

 

It'd be easiest to just have it as a one-dimensional array that you treat like a 2D array:

m_Tile = new uint8[MAP_WIDTH * MAP_HEIGHT];
 
m_Tile[(y * MAP_WIDTH) + x] = blah;

 

 

 

But why not use a one-dimensional std::vector so the memory is managed for you?

std::vector<uint8> m_Tiles(MAP_WIDTH * MAP_HEIGHT);

 

uint8 myClass::GetTile(unsigned x, unsigned y)
{
    return this->m_Tiles[(y * MAP_WIDTH) + x];
}


PARTNERS