传递所有元素为零的数组 (C++)
有一个函数:
void fnc (T arg[]) {
// inside the function there is something like this:
// A = B + arg[index] * C;
}
在某些情况下,没有什么可传递的,因此 arg[] 应该为零。那么,有没有一种方法可以像这样调用函数:void fnc(0);
?
There is a function:
void fnc (T arg[]) {
// inside the function there is something like this:
// A = B + arg[index] * C;
}
In some situations, there is nothing to pass so, arg[]
should be zero. So, is there a way to call function as this way: void fnc(0);
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,您可以调用函数将
null
值,例如:fnc (NULL);
。但请确保在使用函数之前检查函数是否 arg == NULL 。Ps:最好的办法是使用
std::vector
而不是简单的数组。In that case you can call function will
null
value e.g :fnc (NULL);
. But make sure to check in function whetherarg == NULL
or not before using it.P.s: Best thing is to use
std::vector
instead of simple array.