Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7507
| From | Ruben Safir <ruben@mrbrklyn.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | array initiation - methodology for converting C code to C++ |
| Date | 2011-07-06 03:12 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <iv0jqi$alg$2@reader1.panix.com> (permalink) |
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?
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
array initiation - methodology for converting C code to C++ Ruben Safir <ruben@mrbrklyn.com> - 2011-07-06 03:12 +0000
Re: array initiation - methodology for converting C code to C++ 东 苏 <sudongndsl@gmail.com> - 2011-07-06 01:10 -0700
Re: array initiation - methodology for converting C code to C++ Ruben Safir <ruben@mrbrklyn.com> - 2011-07-06 15:00 +0000
Re: array initiation - methodology for converting C code to C++ Michael DOUBEZ <michael.doubez@free.fr> - 2011-07-06 02:56 -0700
csiph-web