【发布时间】:2015-09-24 10:54:07
【问题描述】:
如果我在 C++ 中有一个未分配的对,我想用什么来代替 NULL?
例如,假设我有如下(伪)代码:
pair<int,int> bestPair; //Global variable
updateBestPair(vector<int> a, vector<int> b) {
bestPair = NULL;
for (/* loop through a and b */) {
if (/* pair(a,b) is better than bestPair and better than some baseline */)
bestPair = make_pair(a,b);
}
if (bestPair != NULL) //Found an acceptable best pair
function(bestPair);
else
cout<<"No acceptable pairs found"<<endl;
}
【问题讨论】: