我有一种情况,我有一个 Foo 类型的对象,在这种情况下,调用它自己的方法会以某种方式在“this”中丢失它自己的地址。我已经定义了这些功能:
// Bar has an instance of foo, and wishes to call a function001()...
Bar::doThingWithFoo(){
// foo is at address 0x1a7bbb70 here...
foo->function001();
}
// The definition of function001(). The address of "this" is as expected.
Foo::function001(){
// the address of "this" is 0x1a7bbb70 here...
this->function002();
}
Foo::function002(){
// but the address of "this" is 0xbfffe090 here!!!
// bad things happen, as you might expect.
this->getMyProperty()->doThing();
}
为什么会发生这样的事情?