C ++: Why function parameters cannot be automatic?

For example, the following codes will not be accepted.

void foo(auto i){ cout<<(i+1); } 

I think it should be equivalent to the following accepted codes

 template<typename T> void foo(T i){ cout<<(i+1); } 

Thus, the compiler should be able to deduce (or instantiate) the type of parameters. But why not work?

thanks a lot: -)

+6
source share

Source: https://habr.com/ru/post/974452/


All Articles