0

I'm doing this game assignment for college in c++ and I'm trying to initialize the map (Pos_xy **map - base abstract class) to emptyPos that is a derivate class, although I'm getting this compiler's error

error: invalid conversion from ‘emptyPos**’ to ‘Pos_xy**’

Is this impossible to do ? I know if I just a simple pointer I can do [Pos_xy *c = new emptyPos; ] Is it wrong when we have Pos_xy** instead;

void Game::initMap(){
    map = new emptyPos*[mapCol];
    for (size_t col = 0; col < mapCol; col++)
        map[col] = new emptyPos[mapRow];
}
m3k3r1
  • 15
  • 6
  • at least add code – Raindrop7 Dec 21 '16 at 13:23
  • 3
    Why are you using `new[]` and pointers instead of `std::vector`? – Some programmer dude Dec 21 '16 at 13:23
  • You probably should consider using standard [containers](http://en.cppreference.com/w/cpp/container) & [smart pointers](https://en.wikipedia.org/wiki/Smart_pointer). Your `map` variable should be named otherwise, and could be a `std::vector>` – Basile Starynkevitch Dec 21 '16 at 13:25
  • Also note that you need a *tripple* pointer (`Pos_xy***`) to be able to handle polymorphism. When you assign an `emptyPos` object instance to a `Pos_xy` object instance you will have *object slicing* and lose the polymorphism. If using vectors, you need a vector of vectors of pointers. – Some programmer dude Dec 21 '16 at 13:26

0 Answers0