OCaml是否有能力通过引用传递? [英] Does OCaml have the ability to pass by reference?
本文介绍了OCaml是否有能力通过引用传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C ++中,程序可以将引用而不是值传递给函数.
In C++ a program can pass a reference, not value to a function.
void incrementInt(int &x)
{
++x;
}
OCaml是否提供相同的功能?
Does OCaml offer this same functionality?
推荐答案
不,没有严格的等效项.
No, there is no strict equivalent.
有ref
,类似于指向新分配的内存的指针,并且有对象引用"传递的记录,数组,对象和其他复合数据类型的值,这再次表示它们起作用就像指向新分配的内存的指针.
There are ref
s, which are like pointers to new-allocated memory, and there are records, arrays, objects and values of other compound data types, that are passed "by object reference", which again means they act like pointer to new-allocated memory.
但是,没有等效于指向变量或C ++引用的指针.
However there's no equivalent to a pointer to a variable or a C++ reference.
这篇关于OCaml是否有能力通过引用传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文