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

后端 未结 4 1399
星月不相逢
星月不相逢 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:07

    Templates are the way you do this with normal functions:

    template 
    int function(T data)
    {
        //DOES something
    }
    

    Alternatively, you could use a lambda:

    auto function = [] (auto data) { /*DOES something*/ };
    

提交回复
热议问题