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!h12g2000pro.googlegroups.com!not-for-mail From: =?UTF-8?B?5LicIOiLjw==?= Newsgroups: comp.lang.c++ Subject: Re: array initiation - methodology for converting C code to C++ Date: Wed, 6 Jul 2011 01:10:55 -0700 (PDT) Organization: http://groups.google.com Lines: 69 Message-ID: <5062d7c4-f7db-4749-99c0-ff87b2ef5eee-at-h12g2000pro.googlegroups.com> References: NNTP-Posting-Host: 125.71.231.238 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1309939856 17397 127.0.0.1 (6 Jul 2011 08:10:56 GMT) X-Complaints-To: groups-abuse-at-google.com NNTP-Posting-Date: Wed, 6 Jul 2011 08:10:56 +0000 (UTC) Complaints-To: groups-abuse-at-google.com Injection-Info: h12g2000pro.googlegroups.com; posting-host=125.71.231.238; posting-account=ILWztwoAAADUfCNsev80xBpIqJN8IFRS User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.6; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022),gzip(gfe) Xref: panix comp.lang.c++:1087312
On 7=E6=9C=886=E6=97=A5, =E4=B8=8A=E5=8D=8811=E6=97=B612=E5=88=86, Ruben Sa= fir 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. > > So I tried some variations so I didn't have to alter the internal code > that used the array. =C2=A0Someone told me to make it a static array, but > something happened which I didn't expect. =C2=A0I tried > > screens.h > > =C2=A0class menu_window > =C2=A0 { > =C2=A0 =C2=A0 public: > > =C2=A0 =C2=A0 =C2=A0 /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D =C2=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 */ > =C2=A0 =C2=A0 =C2=A0 menu_window (); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* construct= or =C2=A0 =C2=A0 =C2=A0*/ > =C2=A0 =C2=A0 =C2=A0 menu_window (int height, int width, int row, int col= ); > =C2=A0 =C2=A0 =C2=A0 menu_window ( const menu_window &other ); =C2=A0 /* = copy constructor */ > =C2=A0 =C2=A0 =C2=A0 ~menu_window (); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* destructor= =C2=A0 =C2=A0 =C2=A0 */ > > =C2=A0 =C2=A0 =C2=A0 WINDOW *menu_win; > =C2=A0 =C2=A0 =C2=A0 static char const *choices[5]; > =C2=A0 =C2=A0 =C2=A0 int height; > =C2=A0 =C2=A0 =C2=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])) { > =C2=A0 =C2=A0row_(prow); > =C2=A0 =C2=A0col_(pcol); > =C2=A0 =C2=A0choices[0] =3D "Add a question "; > =C2=A0 =C2=A0choices[1] =3D "Start the Quiz "; > =C2=A0 =C2=A0choices[2] =3D "c "; > =C2=A0 =C2=A0choices[3] =3D "d "; > =C2=A0 =C2=A0choices[4] =3D "Exit "; > =C2=A0 =C2=A0menu_win =3D newwin(height, width, row_(), col_() ); > =C2=A0 =C2=A0keypad(menu_win, TRUE); > =C2=A0 =C2=A0mvprintw(0,0, "Use arrow keys to go up and down, Press enter= to select choice"); > =C2=A0 =C2=A0refresh(); > =C2=A0 =C2=A0print_menu(menu_win, highlight); > > } =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* constructor =C2=A0 =C2=A0 =C2=A0*/ > > and this failed as a static. =C2=A0When I removed static, it works fine. = =C2=A0Why?
static memeber variable should like this Screens::choices[0] =3D "Add a question "; -- end of forwarded message --
|
|