c++ - oFx:使用 mouseEvent 初始化类实例
问题描述
如果我运行此代码,它会给我一个Thread 1: EXC_BAD_ACCESS
.
在topNav.h
文件中:
vector<indicatorButton> indicators;
并在topNav.cpp
文件中
void topNav::setup(ofVec2f p, int n , int *appState) {
// ... other vars here
for(int i = 1 ; i <= quantityOfPages ; i++){
indicators[i-1].setup(i, ofVec2f(padding.x + spacing * i, padding.y ), appState );
}
}
在 indicatorButton.cpp 文件中:
indicatorButton::indicatorButton() {
bRegisteredEvents = false;
}
void indicatorButton::setup(int i, ofVec2f p, int *appState) {
// this will enable our circle class to listen to the mouse events.
if(!bRegisteredEvents) {
ofRegisterMouseEvents(this);
bRegisteredEvents = true;
}
// other variables...blah blah.
}
如果我删除ofRegisterMouseEvents()
它运行良好。除了我没有注册鼠标事件:/
我在这里做错了什么?
解决方案
指点!需要改变这个:
vector<indicatorButton> indicators;
对此
vector<indicatorButton *> indicators;
推荐阅读
- user-interface - three.js GUI 的切换按钮
- c++ - 有没有办法遍历一个结构?
- ios - 在 iOS 中创建低 s ECDSA 签名
- kubernetes - Cassandra pod 的引导时间比预期的要长
- python - 在多个python文件中添加一行代码
- r - 警告信息 glmer
- css - 如何减少 dateTimePicker 的宽度和高度?
- html - 为什么我的 CSS 不适用于我的 html 代码?
- javascript - react-admin: 错误: dataProvider 抛出错误。它应该返回一个被拒绝的 Promise - 容易修复吗?
- google-apps-script - 上传 word 文档和 google app 脚本。将 word doc 转换为 google doc,然后运行 app 脚本清理它?