Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use auto keyword in argument list in C++ 11?

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);
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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) {
    //...
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading