gpt4 book ai didi

c++ - Delphi 中 C++ `const` 返回类型的等价物是什么

转载 作者:行者123 更新时间:2023-11-30 01:57:24 24 4
gpt4 key购买 nike

我有以下 C++ 代码:

标题:(类内)

virtual const bigint &getPopulation() ;

实现:

static bigint negone = -1 ;
const bigint &hlifealgo::getPopulation() {
// note: if called during gc, then we cannot call calcPopulation
// since that will mess up the gc.
if (!popValid) {
if (inGC) {
needPop = 1 ;
return negone ;
} else {
calcPopulation(root) ;
popValid = 1 ;
needPop = 0 ;
}
}
return population ;
}

我把它移植到 Delphi 上,它工作得很好。我仍然对 const 返回类型感到有些困惑。

我可以忽略翻译中的 const 吗,或者这里有什么需要注意的地方吗?

Delphi 中有这个概念的模拟吗?

最佳答案

Delphi 中没有类似的东西。你这里有一个 const 引用。在 Delphi 中没有区分可变引用和常量引用的机制。所有引用都可以用来改变一个对象。所以这不是与 const 返回类型相关的问题,更多的是 Delphi 不支持常量引用。

在将代码从 C++ 移植到 Delphi 时,您别无选择,只能忽略 const 引用。您无法在 Delphi 中区分不同类型的引用,只有一种。

关于c++ - Delphi 中 C++ `const` 返回类型的等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18767360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com