我在使用 c++ 中使用隐藏/显示和附加函数时遇到问题

I'm having trouble with using hide/show and attach functions in c++

本文关键字:函数 遇到 问题 c++ 隐藏 显示      更新时间:2023-10-16

我正在开发一个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,其中hideshowFl_Window的公共成员,但Splash_screenInstructions_screen私下继承了它,使得hideshow只能由这些类本身访问。

    确保在类定义中有的效果

    class Instructions_screen : public Fl_Whatever_Window { /* ... */ }
    

    因为如果没有public限定符,默认情况下继承将是私有的。

相关文章: