gpt4 book ai didi

c++ - 将 `this` 分配给 `MyClass *instance`, `instance->member` 没有引用与 `this->member` 相同的内存

转载 作者:行者123 更新时间:2023-11-28 00:26:06 24 4
gpt4 key购买 nike

<分区>

在我的 cpp 实现中,我有:

static MyClass *instance;

在所有包含范围之外自由 float ( curl {})。我也试过将它初始化为 nullptr。

void MyClass::myMethod() {
instance = this;
LOG("Hello, %d, %d", wList, instance->wList);

上面的日志显示了成员对象指针 wList 的任意位置,但是 instance 应该指向与 this 相同的数据,并且因此是相同的 wList,但事实并非如此。 instance->wList 仍然是 0。这里发生了什么?

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