Is there a way to pass auto as an argument in C++?

后端 未结 4 1398
星月不相逢
星月不相逢 2020-12-01 18:06

Is there a way to pass auto as an argument to another function?

int function(auto data)
{
    //DOES something
}
4条回答
  •  悲&欢浪女
    2020-12-01 18:31

    I dont know when it changed, but currently syntax from Question is possible with c++14:

    https://coliru.stacked-crooked.com/a/93ab03e88f745b6c

    There is only warning about it:

    g++ -std=c++14 -Wall -pedantic -pthread main.cpp && ./a.out main.cpp:5:15: warning: use of 'auto' in parameter declaration only available with -fconcepts void function(auto data)

    With c++11 there is an error:

    main.cpp:5:15: error: use of 'auto' in parameter declaration only available with -std=c++14 or -std=gnu++14

提交回复
热议问题