Find neighbours of a vector To find neighbors of a vector and return array of Vectors which are neighbors of a Vector:
vector&lt;XY&gt; neighboursOf(XY coord){
    short x = coord.x;
    short y = coord.y;

    vector&lt;XY&gt; neighbours;
    neighbours.reserve(9);

    neighbours.push_back(XY(x-1, y));
    neighbours.push_back(XY(x-1, y-1));
    neighbours.push_back(XY(x-1, y+1));

    neighbours.push_back(XY(x+1, y));
    neighbours.push_back(XY(x+1, y-1));
    neighbours.push_back(XY(x+1, y+1));
    neighbours.push_back(XY(x+1, y-1));

    neighbours.push_back(XY(x, y-1));
    neighbours.push_back(XY(x, y+1));

    return neighbours;
}
}

XY is a class which has members x and y:
class XY{
    public:
    XY(short x=0, short y=0);
    short x;
    short y;
};

XY::XY(short x, short y) {
    this-&gt;x = x;
    this-&gt;y = y;
}

The param is Vector of the yellow square, the neighbor array is supposed to be the black squares
The XY class looks like it would be better as a plain struct:
struct XY
{
    short x;
    short y;
};

Then we don't need to declare a constructor, because it can be aggregate-initialised.
I'll assume that your vector is an alias for std::vector here, since there's no definition visible.
Eight of the statements to populate the vector look reasonable.  The duplicate of x+1, y-1 is probably unintended, though.
You might profitably use emplace_back rather than writing those constructors.  We could create the vector directly, with all the element values as its initializer-list:
std::vector&lt;XY&gt; neighboursOf(XY coord)
{
    auto const x = coord.x;
    auto const y = coord.y;

    return { {x-1, y-1}, {x, y-1}, {x+1, y-1},
             {x-1, y  },           {x+1, y  },
             {x-1, y+1}, {x, y+1}, {x+1, y+1} };
}

See how the formatting here helps us see that each neighbour is included exactly once?
It is possible to write a clever loop, but that's going to be harder to read and no more efficient than the straightforward code.
Note that if we have a finite grid, then we might want special behaviour at the edges.  And if we have an infinite grid, we'll suffer arithmetic overflow (Undefined Behaviour) when we reach the limits of short.