Home > Blockchain >  How to use auto keyword in argument list in C 11?
How to use auto keyword in argument list in C 11?

Time:11-05

How to replace auto keyword from the function parameter when there will be multiple type arguments called with this function? because I want to use -std=c 11 and I am getting this error in omnet :

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

void main() {
    get_index(float array1, float var1);
    get_index(int array2, int var2);
}

CodePudding user response:

void get_index(auto s_arra[], auto elem) {
    //...
}

Would be valid only in C 20 (gcc error message is misleading)

previously, you use template the verbose way

template <typename T1, typename T2>
void get_index(T1 s_arra[], T2 elem) {
    //...
}

and probably they use same type, so

template <typename T>
void get_index(T s_arra[], T elem) {
    //...
}
  • Related