在处理 vector.size() aka size_type 时,我可以使用一些帮助来澄清这个奇怪的比较
vector<cv::Mat> rebuiltFaces;
int rebuildIndex = 1;
cout << "rebuiltFaces size is " << rebuiltFaces.size() << endl;
while( rebuildIndex >= rebuiltFaces.size() ) {
cout << (rebuildIndex >= rebuiltFaces.size()) << " , " << rebuildIndex << " >= " << rebuiltFaces.size() << endl;
--rebuildIndex;
}
我从控制台中得到的是
rebuiltFaces size is 0
1 , 1 >= 0
1 , 0 >= 0
1 , -1 >= 0
1 , -2 >= 0
1 , -3 >= 0
如果我不得不猜测,我会说编译器盲目地将rebuildIndex 强制转换为unsigned 和+- 但会导致事情表现得很奇怪,但我真的不确定。有人知道吗?