home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!menudo.uh.edu!lobster!nuchat!moe
- From: moe@nuchat.sccsi.com (Norman C. Kluksdahl)
- Subject: comp.sys.ibm.pc comp.sys.ibm.pc.programmer comp.sys.ibm.pc.misc
- Message-ID: <1993Jan25.214958.29671@nuchat.sccsi.com>
- Summary: cpp class interactions; programming problem
- Organization: South Coast Computing Services, Inc.
- Date: Mon, 25 Jan 1993 21:49:58 GMT
- Lines: 90
-
- I have a small (large) problem with instances of my classes recognizing
- each other. I have enclosed code snippets to exemplify the problem:
-
- I have a main, which has the pointers to the class instances as
- global variables. Two types of class instances are used: a screen handler
- and an array of dcsystem objects. The main program examines the input
- file to determine how many dcsystem instances to create, then assignes
- the pointer to the array of objects. The objects are initialized, which
- happens correctly, then the screen handler is invoked, which will handle
- all screen updates and input events, and will invoke the correct method of
- the dcsystem instances.
-
- The problem is that, while the main loop calls the correct object of the
- dcsystem array, the screen handler gets horribly lost. As a debug, i checked
- the pointer to the dcsystem array, and it is badly lost.
-
- The code is compiled with GCC on a 486 PC.
-
- (NOTE: the code sample below is typed in a hurry, so it may not be precisely
- syntactically correct, but it does compile and parts work without error.)
-
- Any suggestions for further debugging or views into what I may have done
- wrong would be greatly appreciated. Please E-mail responses.
-
- ########### CODE SAMPLE ####################
-
- Dcsys * dcsystem;
- Screen * screen_hdlr;
-
- int numsystems;
-
- main
- {
- *** get the number of systems from the input ***
- dcsystem = new Dcsys[numsystems];
-
- for ( int i = 0; i<numsystems; i++)
- dcsystem[i].init();
-
- *** more initialization stuff ***
-
- screen_hdlr.init();
-
- *** by this point, the whole system is screwed up ***
- }
-
- ***** dcsystem.cc
-
- #include screen.h // definitions for the screen class
-
- extern Dcsys *dcsystem;
- extern Screen *screen_hdlr;
-
- Dcsys
- {
- *** misc class variables ***
- public:
- void init(void);
- void dump(void); // debug module to dump 'this' and values
- // of class variables
- void drawsys(void); // module to draw the given instance
- }
- // methods to do init, dump, and drawsys follow. None of these use
- // the screen methods
-
- ***** screen.cc
-
- #include dcsys.h // definitions for the dcsystem class
-
- extern Dcsys *dcsystem;
- extern Screen *screen_hdlr;
-
- Screen
- {
- **** misc class variables ***
- public:
- void init(void); // this sucker causes no problems; it just sets
- // up the screen
- void drawsys(int i); // this is the problem
- }
-
- Screen::drawsys(int i)
- {
- *** misc setup, all involving screen_hdlr's variables and other methods
-
- dcsystem[i].drawsys(); // this causes seg violations
- }
-
- **********************************************************************
- N. Kluksdahl moe@nuchat.sccsi.com
-