我在使用 c++ 中使用隐藏/显示和附加函数时遇到问题
I'm having trouble with using hide/show and attach functions in c++
我正在开发一个c++游戏,我画了两个窗口,但当我试图在两个窗口之间切换时,我不明白为什么我的代码不工作。我已经创建了两个下一个按钮,它们应该在屏幕之间切换,但我收到了所有显示/隐藏功能的非限定id错误,以及一个错误,告诉我要附加的按钮无法访问附加功能。我确信这是我忽略的一件小事,但任何帮助都将不胜感激!
#include "Splash_screen.h"
#include "Instructions_screen.h"
using namespace Graph_lib;
//Screens
Splash_screen* home_win;
Instructions_screen* instruct_win;
//Buttons
Button* splash_button;
Button* instructions_button;
//Functions
void cb_splash_button();
void cb_instructions_button();
int main() {
home_win = new Splash_screen{Point(100,100), 600, 500, "SSFB"};
instruct_win = new Instructions_screen{Point(100,100), 600, 500, "SSFB"};
Splash_screen.hide();
splash_button = new Button{Point{250,400},100,50,"Next",Callback(cb_splash_button)};
instructions_button = new Button{Point{540, 460}, 50, 30, "Next", Callback(cb_instructions_button)};
home_win->attach(*splash_button);
instruct_win->attach(*instructions_button);
return gui_main();
}
void cb_splash_button() {
Splash_screen.hide();
Instructions_screen.show();
}
void cb_instructions_button() {
Instructions_screen.hide();
//CHANGE LATER
Splash_screen.show();
}
我想它应该在解决以下两个问题后工作:
-
您应该将方法应用于对象,而不是应用于它们的类型。
void cb_splash_button() { home_win->hide(); instruct_win->show(); } void cb_instructions_button() { instruct_win->hide(); //CHANGE LATER home_win->show(); }
-
您似乎在使用FLTK,其中
hide
和show
是Fl_Window
的公共成员,但Splash_screen
和Instructions_screen
私下继承了它,使得hide
和show
只能由这些类本身访问。确保在类定义中有的效果
class Instructions_screen : public Fl_Whatever_Window { /* ... */ }
因为如果没有
public
限定符,默认情况下继承将是私有的。
相关文章:
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 我在 C++ 代码中遇到错误警告:控制到达非空函数 [-Wreturn 类型] 的末尾
- 我在C++中使用 getline() 函数时遇到问题
- 存储另一个函数返回的布尔数组时遇到问题
- 我在解决此错误时遇到问题.我正在努力在主函数中传递数组
- Winsock2:当我尝试发送带有空格的字符串时,该函数在遇到空格时似乎停止发送
- 将结构传递给函数时遇到问题
- 我不明白尝试使用字符串作为函数参数时遇到的错误
- 字数统计函数在将单词添加到一组唯一单词时遇到问题
- 尝试通过多个函数移动数组,但遇到了我不知道如何修复的错误
- 我在生成返回为数不多的模板化参数之一cpp的函数时遇到问题
- 学习C++并在早期示例中遇到错误(在非静态数据成员之前需要构造函数)
- 我在使用字符的函数时遇到了一些问题
- 返回带有另一个类的数据成员的构造函数?遇到转换错误?
- 我在理解 AVX 随机内部函数如何为 8 位时遇到一些问题
- 在使用 std::sort() 和 lambda 函数按属性对 ADT 的向量进行排序时遇到问题
- 在检查传递函数标识符时是否获得模板参数时遇到问题
- 调用基构造函数时遇到问题 - 获取读取访问冲突
- 在使用结构体和用函数填充其变量(使用指针)时遇到问题
- 遇到错误试图在功能型参数中使用void函数的错误