I know that meaning of auto keyword has been changed completely from C++11. But Recently I wrote a following simple program that compiles & runs fine when compiling with =std=c++98 option.
#include <iostream>
void fun(auto int a)
{
a=3;
std::cout<<a<<'\n';
}
int main()
{
fun(3);
}
Orwell Dev C++ IDE gives me warning like following:
[Warning] 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
So, is it fine to use auto for function parameters or should I never use auto like this as in above program to maintain compatibility with C++11?
Until C++ 11 the
autokeyword was a "storage class specifier" whereas with C++ 11 it becomes a type-induction specifier.To answer your question: depending on the C++ standard you use to compile your code, adjust the use of the
autokeyword accordingly. It's not portable across the pre/post C++ 11 boundary of the C++ standard.