GNU MP的最佳替代方案是“返回”的功能某物
因此,假设您要编写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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论