GNU MP的最佳替代方案是“返回”的功能某物

发布于 2025-01-30 21:49:39 字数 295 浏览 1 评论 0原文

因此,假设您要编写C ++程序并实现一个函数,该函数将变量的增量值返回1;您可能会做这样的事情:

int next(int n) {
    return n+1;
}

当尝试使用MPZ_T做同样的事情时,您会注意到编译器抱怨MPZ_T代表数组。因此,需要替代方案。

我会自发地做的是在全局范围中声明所有必需的变量,并使我的函数的返回类型“ void”,以便函数仅修改全球定义的变量。

这很好吗?有更好的选择吗?

编辑:我刚刚发现GMP变量是通过参考传递的。问题解决了。

So, let's say you want to write a C++ program and implement a function which returns the incremented value of a variable by 1; you'd probably do something like this:

int next(int n) {
    return n+1;
}

When trying to do the same thing with mpz_t's, you'll have noticed that the compiler complains about the fact that mpz_t represents an array. Therefore, an alternative is needed.

What I'd do spontaneously is to declare all required variables in the global scope and make the return type of my functions "void", so that the functions only modify globally defined variables.

Is this good? Are there better alternatives?

EDIT: I've just found that GMP variables are passed by reference. Problem solved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文