MESSAGE
DATE | 2011-07-05 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] (fwd) array initiation - methodology for converting C code to C++
|
From owner-hangout-outgoing-at-mrbrklyn.com Tue Jul 5 23:20:05 2011 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix) id 4A33B542B8; Tue, 5 Jul 2011 23:20:05 -0400 (EDT) Delivered-To: hangout-outgoing-at-www2.mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix, from userid 28) id 34FD954300; Tue, 5 Jul 2011 23:20:05 -0400 (EDT) Delivered-To: hangout-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by www2.mrbrklyn.com (Postfix) with ESMTP id E7F96542B8 for ; Tue, 5 Jul 2011 23:20:04 -0400 (EDT) Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 67041332EC for ; Tue, 5 Jul 2011 23:20:38 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 20529) id 55DF833C4A; Tue, 5 Jul 2011 23:20:38 -0400 (EDT) From: Ruben Safir To: hangout-at-nylxs.com Subject: [NYLXS - HANGOUT] (fwd) array initiation - methodology for converting C code to C++ User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386)) Message-Id: <20110706032038.55DF833C4A-at-panix2.panix.com> Date: Tue, 5 Jul 2011 23:20:38 -0400 (EDT) Sender: owner-hangout-at-mrbrklyn.com Precedence: bulk Reply-To: hangout-at-mrbrklyn.com
-- 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 --
|
|