Const-correctness with getters of vector of non-pointers

I have a quick question regarding const-correctness for getters of vector of non-pointers. Basically, I have this class with a non-const getter and a const getter for m_Vertices: class Mesh { public: std::vector<Vertex>& GetVertices() { return m_Vertices; } const std::vector<Vertex>& GetVertices() const { return m_Vertices; } private: std::vector<Vertex> m_Vertices; } The non-const getter makes sense… Read More Const-correctness with getters of vector of non-pointers

Advice for getting a pointer to an object from a vector stored inside a class

class Element { class Point { private: double x; double y; public: //getters/setters for x and y }; private: std::string name; std::vector<Point> values; public: void insertValue(unsigned int index, double x, double y); … }; class Collection { private: std::string name; std::vector<Element> elements; public: … … Element* elementAt(unsigned int index) const { return const_cast<Element*>(&elements.at(index)); } };… Read More Advice for getting a pointer to an object from a vector stored inside a class