你好,我正在使用C++内置算法。我有这样的代码在这里:为什么我不能在我的函数中使用const qualfier?
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
bool isDon(string& name) const {
return name == "Don";
}
string names[] = {"George", "Don", "Estelle", "Mike", "Bob"};
int main() {
string* ptr;
ptr = find_if(names, names+5, isDon);
return 0;
}
当我运行这个程序,编译器给我一个错误,在我的isDon()
功能decleration所在,它说,我不能在功能decleration使用CV-预选赛。这是为什么?
你所期望的'const'做,如果它被允许什么“一个const修饰词只能用于类非静态成员函数中使用”? – juanchopanza