内部方法但循环仍然出现预期的不合格 ID 错误 C++

Inside method but loop still getting expected unqualified-id error C++

我有一个简短的问题。我已经阅读了 "expected unqualified-id" 错误以及当循环在方法之外时它们是如何发生的。我遇到的问题是循环是 inside 一个方法,我仍然得到这个?如有任何帮助,我们将不胜感激。

编译器错误:

   expected unqualified-id
for(auto template : filtered) {
         ^

代码:

py::str process(string text){
    //some code...
    for(auto template : filtered) {
        //some more....
    }
    //a return
}

template is a reserved keyword。这是您不允许使用的少数名称之一。将 template 变量的名称更改为任何合法标识符以解决您的问题。例如,尝试:

py::str process(string text){
    //some code...
    for(auto my_template : filtered) {
        //some more....
    }
    //a return
}