通过引用传递向量,但更改不会粘贴c ++

0 c++ scope reference vector

void RemoveGreenEffect::processImage(vector<Point>& points)
{
    for (int i = 0; i < points.size(); ++i)
    {
        points[i].setGreen(0);
    }
}
Run Code Online (Sandbox Code Playgroud)

此函数正确引入向量并在本地进行更改.但是,当程序返回main时,它不会保留更改.有人可以解释我做错了吗?如果有帮助,这里是main的调用函数.

for (int i = 0; i < ppm.getRows(); ++i)
{
    my_effect->processImage(picture.getPicture()[i]); 
}
Run Code Online (Sandbox Code Playgroud)

my_effect是一个基类指针,指向派生对象RemoveGreenEffect.getPicture()是Point对象向量的向量,因此getPicture()[i]是Point类的向量.目标是一次一行地删除图片中的所有绿色值像素,但同样,更改仅在本地工作.

编辑,这是getPicture()

vector<vector<Point>> PointFormatPicture::getPicture()
{
return _picture;
}
Run Code Online (Sandbox Code Playgroud)

这是_picture是什么

vector<vector<Point>> _picture;
Run Code Online (Sandbox Code Playgroud)

use*_*165 5

更改为按引用返回:

vector<vector<Point>>& PointFormatPicture::getPicture()
{
   return _picture;
}
Run Code Online (Sandbox Code Playgroud)