delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/29/22:52:20

From: Mark Goodwin <mgoodwin AT cray DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A very newbie question. Very newbie.
Date: Tue, 29 Jul 1997 10:33:16 -0500
Organization: Cray Research a division of Silicon Graphics, Inc.
Lines: 39
Message-ID: <33DE0D3C.794B@cray.com>
References: <01bc9bae$0a7b5180$6d3d31cf AT default>
NNTP-Posting-Host: fsgi091.cray.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Majisun wrote:
> 
> Alright, this may sound stupid, but I forgot how to define an array.
> 
> is this how you do it:
> 
>         class star
>                 {
>                 /* star stuff here*/
>                 }
>         star starfield[100];
> 
> If so, how come it says
> error: don't know how much storage space for starfield, and points me to
> the line above?


Is your class definition of star and the starfield declaration in
the same file?  What's happening is the C++ processor reaches the
starfield declaration before it gets the full definition of class
star.

You could put the star class definition in a header file called
star.h, for example, and put the starfield declaration either in
an implementation file which includes star.h or in another header
file which includes star.h  The main thing to watch for is that
the entire star class definition gets processed before the starfield
declaration.

As a test, try this...put class star at the top of main.cc. Then put
main() after this class definition and put your starfield declaration
inside main().  It should work then.  You could also declare starfield
in the following manner:

   star starfield = new star[100];

Hope this helps.

Mark Goodwin

- Raw text -


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