我正在尝试使用unordered_set
C++ 标准库中的一个。我正在使用 std 命名空间。
using namespace std;
这unordered_set
是在我的功能范围内。我想用它来记忆一些值。
int do_crazy_calculations(int n) {
static unordered_set<int> done_before;
done_before::iterator node_found = done_before.find(n);
// n has not been seen before, so do calculations and memoize the result.
if (node_found == done_before.end()) {
int result = actually_do_calculations(n);
done_before.insert(n, result);
return result;
}
// n has already been seen before, just return the memoized value.
else {
return node_found.get();
}
}
但是,我收到此编译错误:
CplusplusExperiment.cpp:在函数中
'int do_crazy_calculations(int)'
:
CplusplusExperiment.cpp:10:10:错误:'unordered_set'
未命名类型
make:*** [CplusplusExperiment.o] 错误 1
但是,我确实分配了一个类型unordered_set
-int
对吧?这个错误是什么意思?