c++ - 在哪里声明应用程序中使用的变量(wxWidgets)?
问题描述
我创建了MyApp
继承自wxApp
并添加了一些组件变量的类:
class MyApp : public wxApp {
GameBoard* gb;
Player* player;
bool lightTheme;
std::vector<wxBitmapToggleButton *> cardImages;
public:
MyApp();
virtual bool OnInit();
void displayImages(wxFrame *, wxGridSizer *);
void OnCardSelect(wxCommandEvent&);
};
然后我将它们的值设置为MyApp::OnInit
:
void MyApp::OnInit() {
//...
player = new Player(1);
//...
}
当我Player
在函数中使用类方法时MyApp::OnInit
,一切正常,但是当我在事件函数中使用它时,我得到了奇怪的结果(例如,在类中声明的空 大小返回 18446744073709551540)。事件功能:std::vector<int>
Player
void MyApp::OnCardSelect(wxCommandEvent& event) {
std::cout << (player->getChosen()).size() << std::endl;
// above line only for debugging, getChosen() returns const std::vector<int>&, which should be empty, but it print strange result
wxBitmapToggleButton *selectedCard = dynamic_cast<wxBitmapToggleButton *>(event.GetEventObject());
player -> toggleChosen(int(selectedCard -> GetId()));
}
MyApp
调用后OnInit
(使用)的组件变量发生了什么IMPLEMENT_APP(MyApp)
,我应该在哪里声明和更改这些变量的值?
解决方案
推荐阅读
- json - 使用 Clojure 将 json 对象上传到 S3?
- python - Tornado GET 套接字挂断
- java - 无法从实体 Spring Boot 生成表
- angular - 单击表单中的提交时出现“错误类型错误:无法读取 null 的属性‘必需’”(使用 Angular 进行验证)
- c# - 开始参数:属性“命令行参数”的参数太长(Microsoft Visual Studio)
- machine-learning - 如何计算整个数据集的 mAP(平均精度)?
- android - 在 Android Studio 中的 Flutter 上运行模拟器时出错
- css - 如果我们使用 SASS,应该在 react tsx 中导入哪些文件?
- python-3.x - 如何标准化 BERT 分类器的输出
- swift - 如何在 Xcode 12 beta 3 中使用 Swift 成功导入 AVFoundation?