Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7507
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!not-for-mail |
|---|---|
| From | Ruben Safir <ruben@mrbrklyn.com> |
| 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 | <iv0jqi$alg$2@reader1.panix.com> (permalink) |
| 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@panix.com |
| NNTP-Posting-Date | Wed, 6 Jul 2011 03:12:18 +0000 (UTC) |
| User-Agent | Pan/0.133 (House of Butterflies) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:7507 |
Show key headers only | View raw
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