传递所有元素为零的数组 (C++)

发布于 2025-01-06 21:29:36 字数 236 浏览 2 评论 0原文

有一个函数:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2025-01-13 21:29:36

在这种情况下,您可以调用函数将 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 whether arg == NULL or not before using it.

P.s: Best thing is to use std::vector instead of simple array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文