这里是我的代码:奇怪的错误:EXC_BAD_ACCESS在我的课
typedef struct TItemSelector{
ItemSelectFrame* pItems[2];
} SItemSelector;
class item {
public:
void expMethod();
SItemSelector itemSelector_;
UILayerButton* startBtn_;
};
void item::expMethod(){
startBtn_ = new UILayerButton();
for (i = 0; i < 3; i++) {
itemSelector_.pItems[i] = new ItemSelectFrame();
}
startBtn_->callMethodA();
}
void UILayerButton::callMethodA()
{
this->callMethodB();
}
void UILayerButton::callMethodB()
{
}
在this->callMethodB();
,一个 “EXC_BAD_ACCESS” occoured。
之后,我发现了一个变通办法:
class item {
public:
void expMethod();
SItemSelector itemSelector_;
SItemSelector itemSelector2_; // work around
UILayerButton* startBtn_;
};
然后一切顺利的话......我只是不知道发生了什么,但callMethodB()
只是一个空方法,有什么关系呢。
我正在使用Apple LLVM 3.1,默认设置。
更新:修复了我的代码。
呃,关于EXC_BAD_ACCESS有什么“奇怪的”?你在某处使用了一个无效指针。 (你在哪里设置startBtn_?) – 2012-04-28 13:25:57
Sry我错过了一条线,修复了。 @HotLicks – 2012-04-28 13:39:12
很难分辨你发布的内容。你可以添加'UILayerButton'的定义吗? – starbugs 2012-04-28 13:42:47