You could also use size_type
for the index - the same type as your vector:
// Make your own type for the index based on the vector's index type
typedef std::vector<X>::size_type size_type;
// Use your typedef in the declaration of your getter
X getVectorElement(size_type index);
Returning a copy is a good idea - in fact, it's the best thing to do if you want to hide the vector from your callers. Returning a pointer or a reference may be more performant, but it opens up your class to backdoor manipulations, in cases when X
is mutable. It also creates an issue if the vector is modified after a reference has been returned, because changing the vector invalidates references to its elements.
You can provide individual functions for manipulating attributes of X
, but you could also provide a setter that lets users replace an element of your vector.