我有这个方法:
void Session::onNewImage(cv::Mat& img, double elapsedTime){
static int count = 0;
add(img, dnnOutput[count++], curLati, curLongi, curAlti, curHeading, curRoll);
}
它已被调用 1400 次。每次增加“计数”的值。但是当它到达 1401 时,我希望“计数”变为 0 ,然后在那里再次增加形式。我不希望“计数”成为全局变量。我怎样才能做到这一点?
附言我不能将它硬编码为 1400。每次都可能不同。还有另一种方法决定调用此方法的次数,具体取决于作为该方法输入的图像数量。
最佳答案
应该这样做:
void Session::onNewImage(cv::Mat& img, double elapsedTime){
static int count = 0;
if (count >= getYourCountLimitFromSomewhere())
count = 0;
add(img, dnnOutput[count++], curLati, curLongi, curAlti, curHeading, curRoll);
}
请注意,正如@Aconcagua 在评论中指出的那样,count
与阈值的比较是通过 >
还是 >=
取决于 getYourCountLimitFromSomewhere()
返回值的含义。
关于c++ - 每次调用方法时增加变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51890216/