//if (this->positions [position->getX()+1][position->getY()]);
// if (this->positions [position->getX()][position->getY()-1]);
// if (this->positions [position->getX()-1][position->getY()]);
// if (this->positions [position->getX()][position->getY()+1]);
No one has answered in part because what you are doing seems a little convoluted, and also because what you are asking is not entirely clear.
If I understand correctly, you have a 2D array/vector/something where each element may be a “wall” or not-a-wall/something-else.
So, what is this function’s purpose?
I think it is trying to solve something that is not well defined.
For example, your 2D maze vector/array/whatever should be designed such that it is impossible to reach the edges without first hitting a wall. This should be a design prerequisite. This would simplify a whole lot of stuff in your code.