MESSAGE
DATE | 2011-07-07 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] (fwd) Re: array initiation - methodology for converting C code to C++
|
-- forwarded message -- Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!v10g2000yqn.googlegroups.com!not-for-mail From: Michael DOUBEZ Newsgroups: comp.lang.c++ Subject: Re: array initiation - methodology for converting C code to C++ Date: Wed, 6 Jul 2011 02:56:57 -0700 (PDT) Organization: http://groups.google.com Lines: 78 Message-ID: <453f3d6d-dd59-475f-ab2b-c91467b257f1-at-v10g2000yqn.googlegroups.com> References: NNTP-Posting-Host: 62.160.54.163 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1309946217 16143 127.0.0.1 (6 Jul 2011 09:56:57 GMT) X-Complaints-To: groups-abuse-at-google.com NNTP-Posting-Date: Wed, 6 Jul 2011 09:56:57 +0000 (UTC) Complaints-To: groups-abuse-at-google.com Injection-Info: v10g2000yqn.googlegroups.com; posting-host=62.160.54.163; posting-account=4_dwSAoAAAD_OEYz89wEMQOvnJlm6isC User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESRCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0,gzip(gfe) Xref: panix comp.lang.c++:1087318
On Jul 6, 5:12=A0am, Ruben Safir wrote: > I had some C style code that essentially had > > const char * choices[] =3D {"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.
No but it can be afterward: class menu_window {
static char const * const choices[]; };
char const * const menu_window::choices[] =3D {"Choice A", "Choice B", "Choice C", "Choice D"};
> So I tried some variations so I didn't have to alter the internal code > that used the array. =A0Someone told me to make it a static array, but > something happened which I didn't expect. =A0I tried > > screens.h > > =A0class menu_window > =A0 { > =A0 =A0 public: > > =A0 =A0 =A0 /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =A0LIFECYCLE =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ > =A0 =A0 =A0 menu_window (); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 /* constructor =A0 =A0 =A0*/ > =A0 =A0 =A0 menu_window (int height, int width, int row, int col); > =A0 =A0 =A0 menu_window ( const menu_window &other ); =A0 /* copy constru= ctor */ > =A0 =A0 =A0 ~menu_window (); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0/* destructor =A0 =A0 =A0 */ > > =A0 =A0 =A0 WINDOW *menu_win; > =A0 =A0 =A0 static char const *choices[5]; > =A0 =A0 =A0 int height; > =A0 =A0 =A0 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])) { > =A0 =A0row_(prow); > =A0 =A0col_(pcol); > =A0 =A0choices[0] =3D "Add a question "; > =A0 =A0choices[1] =3D "Start the Quiz "; > =A0 =A0choices[2] =3D "c "; > =A0 =A0choices[3] =3D "d "; > =A0 =A0choices[4] =3D "Exit "; > =A0 =A0menu_win =3D newwin(height, width, row_(), col_() ); > =A0 =A0keypad(menu_win, TRUE); > =A0 =A0mvprintw(0,0, "Use arrow keys to go up and down, Press enter to se= lect choice"); > =A0 =A0refresh(); > =A0 =A0print_menu(menu_win, highlight); > > } =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* construct= or =A0 =A0 =A0*/ > > and this failed as a static. =A0When I removed static, it works fine. =A0= Why?
Did it fail at link time ? If so, it is because you have declared it but not defined it.
-- Michael -- end of forwarded message --
|
|