How-to return a const std::vector<Object *const>?

后端 未结 5 1226
北恋
北恋 2021-01-25 06:37

I have a class with a container (containing pointer) as a member:

MyClass{
private:
   std::vector _VecMyObjs;
public:
   const std::vector

        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-01-25 07:00

    const vector MyClass::GetVecMyObjs() const
    {
       return vector(_VecMyObjs.begin(), _VecMyObjs.end());
    }
    

    This seems to be the solution to me. I can tell now, thanks to all the different posts I got. Thanks all of you! Have a nice one... (Or let me know, if I am still wrong somewhere.)

提交回复
热议问题