有没有办法将自动作为参数传递给C ++? [英] Is there a way to pass auto as an argument in C++?

查看:151
本文介绍了有没有办法将自动作为参数传递给C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将auto作为参数传递给另一个函数?

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

int function(auto data)
{
    //DOES something
}


推荐答案

如果您希望这意味着您可以将任何类型传递给函数,请将其设为模板:

If you want that to mean that you can pass any type to the function, make it a template:

template <typename T> int function(T data);

有一个C ++ 17的提议允许您使用的语法(因为C ++ 14已经对于通用lambda表达式),但它不是标准的。

There's a proposal for C++17 to allow the syntax you used (as C++14 already does for generic lambdas), but it's not standard yet.

这篇关于有没有办法将自动作为参数传递给C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆