0
我正在使用ncurses,并且正在尝试创建一个将打印一个框的类。 我班未初始化的两个实例之一
class CMenu{
public:
CMenu(int x , int y){
this -> x = x;
this -> y = y;
createMenu();
}
void createMenu(){
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
my_menu_win = newwin(30, 60, x, y);
keypad(my_menu_win, TRUE);
/* Print a border around the main window and print a title */
box(my_menu_win, 0, 0);
mvprintw(LINES - 2, 0, "F2 to exit");
refresh();
wrefresh(my_menu_win);
while(true){
switch(c = wgetch(my_menu_win)){
case KEY_F(2):
endwin();
exit(1);
case KEY_DOWN:
break;
case KEY_UP:
break;
case 10:
move(20, 0);
clrtoeol();
wrefresh(my_menu_win);
refresh();
break;
}
wrefresh(my_menu_win);
}
}
private:
int n_choices;
int i;
int index;
int c;
int x;
int y;
WINDOW *my_menu_win;
};
和类,我想创建实例说类
class CUI{
public:
CUI(){
min_X = 200;
min_Y = 50;
}
void printBackground(){
start_color();
init_pair(1,COLOR_GREEN,COLOR_BLACK);
attron(COLOR_PAIR(1));
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(1));
mvhline((y/5) - 1, (x/6), ACS_BOARD , 140);
mvhline((y/5)*4, (x/6), ACS_BOARD , 140);
}
void initMenu(){
initscr();
printBackground();
left = new CMenu(10,35);
right = new CMenu(10,115);
refresh();
endwin();
}
private:
int min_X;
int min_Y;
int x;
int y;
CMenu *left;
CMenu *right;
};
及主要
int main() {
CUI one;
one.initMenu();
return 0;
}
的问题是,只有盒子的一个变打印。我将cout
添加到CMenu类的构造函数中,以查看它们是否都被调用。只有一个实例被调用,第二个实例被调用。这是什么造成的?为什么两个实例都被调用?