Vector Iterators Incompatible

后端 未结 10 1001
别那么骄傲
别那么骄傲 2020-12-04 23:54

I have a class with a std::vector data member e.g.

class foo{
public:

const std::vector getVec(){return myVec;} //other stuff omitted

private:
s         


        
10条回答
  •  庸人自扰
    2020-12-05 00:49

    The problem is that you always return another copy of the vector. Use a reference:

    const std::vector& getVec(){return myVec;} //other stuff omitted
    

提交回复
热议问题