Efficiency of public access vector

In the following example class A is defined below, and class B is some unspecified type (if it makes a big difference what B is, please say so, for now just assume that's a sufficiently complicated type).

If I have something like
1
2
3
4
5
6
class A1 {
  public:
    const std::vector<B>& getV() const {return v;}
  private:
    std::vector<B> v;
};

vs.
1
2
3
4
5
class A2 {
  public:
    A() { /*populate v*/ }
    std::vector<B> v;
};


Will calling "a2_obj.v" make a copy of the each element (slow), or would it be like returning a reference like in the A1 class's accessor function a1_obj.getV() except it won't be const?
Last edited on
Topic archived. No new replies allowed.