gpt4 book ai didi

C++ 参数是指向常量对象的指针,但未返回更新的对象?

转载 作者:太空狗 更新时间:2023-10-29 23:54:06 25 4
gpt4 key购买 nike

我的原生 C++ 类 SrcClass 包含以下内容:

std::vector<shotEntry> objectsQueue;

bool getRelatedEntry(const entryToProcess *entriesDeets, int &i) const {
if (i >= (int)objectsQueue.size()) {
i = 0;
return false;}
if (!objectsQueue.size()) return false;
entriesDeets = &(objectsQueue[i++]);
return true;
}

在我的客户中我有:

const entryToProcess *entriesDeets = NULL;
int i = 0;
while (srcObj->getRelatedEntry(entriesDeets, i)) {

当我单步执行 getRelatedEntry 形式参数时,entriesDeets 在返回之前按预期更新。返回时客户端的实际参数没有更新。

这是我离开两个月后回到的某个大项目。我很确定我所做的最后一次重构是引入这些该死的 vector 。当我弄乱标题时,编译需要很长时间。我是否对 C# 的初始化一次/只读/常量感到困惑?我可以让客户端取回只读 native 对象吗?

最佳答案

这是因为您正在设置函数参数的值。你想要:

bool getRelatedEntry(const entryToProcess **entriesDeets, int &i) const {
...
*entriesDeets = &(objectsQueue[i++]);
...

srcObj->getRelatedEntry(&entriesDeets, i)

关于C++ 参数是指向常量对象的指针,但未返回更新的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7890452/

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