如何在 C++ 11 的参数列表中使用 auto 关键字?

Ab *_*yia 1 c++ auto

当函数调用多个类型参数时,如何替换函数参数中的 auto 关键字?因为我想使用-std=c++11并且在 omnet++ 中收到此错误:

**error: use of auto in parameter declaration only available with -std=c++14 or -std=gnu++14**  
Run Code Online (Sandbox Code Playgroud)
void get_index(auto s_arra[], auto elem) {
    ...
}

void main() {
    get_index(float array1, float var1);
    get_index(int array2, int var2);
}
Run Code Online (Sandbox Code Playgroud)

Jar*_*d42 5

void get_index(auto s_arra[], auto elem) {
    //...
}
Run Code Online (Sandbox Code Playgroud)

仅在 C++20 中有效(gcc 错误消息具有误导性)

以前,您以详细的方式使用模板

template <typename T1, typename T2>
void get_index(T1 s_arra[], T2 elem) {
    //...
}
Run Code Online (Sandbox Code Playgroud)

并且可能他们使用相同的类型,所以

template <typename T>
void get_index(T s_arra[], T elem) {
    //...
}
Run Code Online (Sandbox Code Playgroud)