我在一个scene:AbsentSolidScene 中根据需要动态加载一个LevelView,该对象是继承CCLayer的
现在我在LevelView的一个button添加事件:
switchButton->addTouchEventListener(this, toucheventselector(AbsentSolidScene::swith2multiopPanel)); //一般情况下我都是这样使用的: //switchButton->addTouchEventListener(this, toucheventselector(LevelView::swith2multiopPanel)); ``` 在执行AbsentSolidScene对象的swith2multiopPanel方法时候,可以很清楚的看到,this对应的是LevelView* 类型的对象。 上面说的都很好理解,问题是: 当我用this去访问AbsentSolidScene对象的时候,居然能访问到AbsentSolidScene对象的属性值,而且还是正确的属性值,不是默认的。 于是我又糊涂了,这个this,到底是什么? 最后贴出两次调用button事件的日志 Cocos2d: AbsentSolidScene swith2multiopPanel() Cocos2d: got this pointer: 0x8681940 Cocos2d: got this->buttonArray 0x44cd7c Cocos2d: AbsentSolidScene swith2multiopPanel() Cocos2d: got this pointer: 0x176067b0 Cocos2d: got this->buttonArray 0x44cd7c ------------------ 很明显在 swith2multiopPanel() 方法中,this每次对应的都是LevelView的内存地址(该对象用掉后根据需要再新增出来,所以地址每次都不同) 而got this->buttonArray 0x44cd7c ,这个buttonArray是AbsentSolidScene对象中的CCArray,在csene的Onenter()中组装,以后就不变了,所以地址每次都相同。 我的猜想: 难道c++的selector机制会自动找到系统中唯一的对象,然后再调用该对象的属性值? 谁能解释下这个现象?困惑我一天了。

