jeudi 27 avril 2017

c++ use shared_ptr to 2-d array of unknown size as input to function

I'm trying to implement Dijkstras algoritm on a map consisting of tiles (i.e. an area of 6x6 m consisting of 40x40 cm blocks who are acessible or walls) and to do that i need to calculate the distance between two tiles. I have created two classes Tile and Dij_Tile where the Tile class is the actual/physical tile containing position etc. and Dij_Tile class contains a shared_ptr to it's Tile representative aswell as reach cost etc.

I have in my test file(using catch.hpp to create a test file) an array with all the tiles (called all_tiles_test) which is an 2-d array containing all the tiles.

Thereafter I create a pointer(shared_ptr) to this array (called all_tiles_test_ptr).

After that I want to send all_tiles_test_ptr to a function who calculate the distance between two tiles. The problem is I don't know how to declare the input to the function where the input is a shared_ptr to an 2-d array of unknown(at the time of coding) size. How should i do that?

Declarations in the test file:

 std::shared_ptr<Tile> all_tiles_test[2][2];
 auto all_tiles_test_ptr(all_tiles_test);

The function, which lies in another file (Tile_Distance .h and .cc):

double tile_dist(std::shared_ptr<Dij_Tile> start_dij_tile_ptr,
     std::shared_ptr<Dij_Tile> end_dij_tile_ptr,
     std::shared_ptr<???> all_tiles_ptr);

where ??? is the part I don't know how to implement.

Aucun commentaire:

Enregistrer un commentaire