www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/29/07:46:02

From: jstacey AT plato DOT wadham DOT ox DOT ac DOT uk (J-P)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Array of home-made class, C++ game
Date: 29 May 2000 12:40:24 +0100
Organization: Wadham College Oxford
Lines: 40
Message-ID: <8gtkv8$vct$1@plato.wadham.ox.ac.uk>
References: <8grfga$h00$1 AT nnrp2 DOT deja DOT com>
NNTP-Posting-Host: plato.wadham.ox.ac.uk
X-Trace: news.ox.ac.uk 959600424 7818 163.1.164.74 (29 May 2000 11:40:24 GMT)
X-Complaints-To: newsmaster AT ox DOT ac DOT uk
NNTP-Posting-Date: 29 May 2000 11:40:24 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <8grfga$h00$1 AT nnrp2 DOT deja DOT com>,  <joel_hansell AT my-deja DOT com> wrote:
>In C++ class, I'm supposed to write a simple
>slalom game. 

Chances are that if you can pare down the code to the bit that causes the
crash, and repost it in comp.lang.c++, it'll be obvious to them,
especially if it's just a pointer problem that's stomping all over the
stack.

If you want to debug using gcc/RHIDE, it has its own very useful debugging
tool. Without wanting to be patronising, look at the "Debug" menu. F7/F8
combinations allow you to step through the code until *pow* - you get a
segmentation fault at the offending line.

>    Port level[]; /* array of Ports, should this
>be "Port* level[]" or even "Port[] level"?
>Perhaps I must define the size of the array, like
>"Port* level[5]"? /*

What you might want to do is define a pointer, Port *level. This pointer
can then be made to point to an array of any size you want with: 

  level = new Port[5];

  // ... 

  delete level[];

  // ...

  level = new Port[250];

Simply declaring Port level[] isn't (I think) proper C++; certainly it
rings alarm bells from this C programmer, but C++ is still a closed book
to me.

So: you can declare Port level[10], or Port *level, where the latter
allows you to change the size of the array starting at address "level".

J-P

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019