MESSAGE
DATE | 2011-07-05 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] (fwd) array initiation - methodology for converting C code to C++
|
-- forwarded message -- Path: reader1.panix.com!panix!not-for-mail From: Ruben Safir Newsgroups: comp.lang.c++ Subject: array initiation - methodology for converting C code to C++ Date: Wed, 6 Jul 2011 03:12:18 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 54 Message-ID: NNTP-Posting-Host: www2.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1309921938 10928 96.57.23.82 (6 Jul 2011 03:12:18 GMT) X-Complaints-To: abuse-at-panix.com NNTP-Posting-Date: Wed, 6 Jul 2011 03:12:18 +0000 (UTC) User-Agent: Pan/0.133 (House of Butterflies) Xref: panix comp.lang.c++:1087304
I had some C style code that essentially had
const char * choices[] = {"Choice A", "Choice B", "Choice C", "Choice D"};
Now this is obviously a problem in a class framework as it can not be initialized in the class definition.
So I tried some variations so I didn't have to alter the internal code that used the array. Someone told me to make it a static array, but something happened which I didn't expect. I tried
screens.h
class menu_window { public:
/* ==================== LIFECYCLE ======================================= */ menu_window (); /* constructor */ menu_window (int height, int width, int row, int col); menu_window ( const menu_window &other ); /* copy constructor */ ~menu_window (); /* destructor */
WINDOW *menu_win; static char const *choices[5]; int height; int width; ....
}
screens.cpp
Screens::menu_window::menu_window (int pheight, int pwidth, int prow, int pcol): height(pheight), width(pwidth), highlight(1), choice(0) , n_choices(sizeof(choices)/ sizeof(choices[0])) { row_(prow); col_(pcol); choices[0] = "Add a question "; choices[1] = "Start the Quiz "; choices[2] = "c "; choices[3] = "d "; choices[4] = "Exit "; menu_win = newwin(height, width, row_(), col_() ); keypad(menu_win, TRUE); mvprintw(0,0, "Use arrow keys to go up and down, Press enter to select choice"); refresh(); print_menu(menu_win, highlight);
} /* constructor */
and this failed as a static. When I removed static, it works fine. Why? -- end of forwarded message --
|
|