德尔福中C++“const”返回类型相当于什么
What's the equivalent of C++ `const` return types in Delphi
我有以下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 ;
}
我把它移植到德尔福,它工作得很好。我仍然对常量返回类型感到有些困惑。
我可以忽略翻译中的const
,还是这里有什么需要注意的?
德尔福有这个概念的类似物吗?
在德尔福没有类似的内容。您在这里拥有的是const
参考。在德尔福中,没有区分可变引用和常量引用的机制。所有引用都可用于改变对象。因此,这不是与const
返回类型相关的特别问题,而是Delphi不支持常量引用。
在将代码从C++移植到 Delphi 时,您别无选择,只能忽略const
引用。您无法区分德尔福中不同类型的引用,只有一个。
相关文章:
- 如何获取std::result_of函数的返回类型
- 奇怪的结构&GCC&clang(void*返回类型)
- 如何建立使用模板函数的lambda函数的尾部返回类型
- 相当于LocaleMatcher的ICU4C
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 函数作为模板参数,是否对返回类型强制约束
- 如何定义依赖于参数包转换的函数的返回类型
- 为什么C++哈希函数的返回类型是 std::size_t,而不是独立于平台的类型?
- C++中的数据类型相当于 vb6 中的常量货币
- 使 sfinae 适用于具有推导返回类型的函数
- 如何使用类型专用化模板方法,该类型本身就是一个模板,其中只有返回类型依赖于模板类型
- 返回类型的声明类型时,应用于三元(?:)表达式
- 使返回类型依赖于调用源
- Haskell相当于C++模板而不是非类型
- 德尔福中C++“const”返回类型相当于什么
- 相当于enum类型的boost::program_options::bool_switch
- 将using语句应用于函数的返回类型,而不应用于整个命名空间
- 相当于 "bool DllMain()" 的 c/c++ Linux - 但我需要将 failure 返回给 dlopen()