So, although gcc allows auto as a parameter in functions, this is not part of C ++ 14, but part of concept-lite , which can become part of C ++ 1z according to the latest Herb Sutter post.
I believe gcc allows this as an extension, and if we compile your program with -pedanticgcc will warn:
warning: ISO C++ forbids use of 'auto' in parameter declaration [-Wpedantic]
auto func(auto x)
^
, , :
auto func(auto x)
{
std::cout << x << std::endl;
return x.getx();
}
:
template <typename T1>
auto func(T1 x)
{
std::cout << x << std::endl;
return x.getx();
}
, , x int. , gcc ( ):
error: request for member 'getx' in 'x', which is of non-class type 'int'
return x.getx();
^
5.1.1 [dcl.fct]:
- , . [: . -end note] [: ,
auto f(auto x, const Regular& y);
template<typename T1, Regular T2>
auto f(T1 x, const T2&);
-end ]