1
我有一个Shapes向量,Shape是我写的类。在keyDown函数中,我遍历这个Shapes矢量并将bool属性background,更新为true。但是,似乎并没有坚持这一改变。C++(cinder):无法更新keyDown函数中的对象属性
主类:
vector<Shape> mTrackedShapes;
void CeilingKinectApp::keyDown(KeyEvent event)
{
// remove all background shapes
if (event.getChar() == 'x') {
for (Shape s : mTrackedShapes) {
s.background = true;
}
}
}
Shape.h
#pragma once
#include "CinderOpenCV.h"
class Shape
{
public:
Shape();
int ID;
double area;
float depth;
cv::Point centroid; // center point of the shape
bool matchFound;
bool moving;
bool background;
cinder::Color color;
int stillness;
float motion;
cv::vector<cv::Point> hull; // stores point representing the hull of the shape
int lastFrameSeen;
};
Shape.cpp
#include "Shape.h"
Shape::Shape() :
centroid(cv::Point()),
ID(-1),
lastFrameSeen(-1),
matchFound(false),
moving(false),
background(false),
stillness(0),
motion(0.0f)
{
}
它通过注册keyDown事件,并正确地进行迭代矢量,b背景属性仍然是错误的。我究竟做错了什么?
是在副本上更改属性,而不是一个!非常感谢你,我不能相信我错过了 – Kat