delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/30/18:37:56

Message-ID: <33DFC2DB.356A@lr.net>
Date: Wed, 30 Jul 1997 18:40:27 -0400
From: Isaac Waldron <waldroni AT lr DOT net>
Reply-To: waldroni AT lr DOT net
Organization: The Computer Nerd
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Accessing Variables

Does anyone know if it is possible to create a variable in a function,
and then access it outside of that function.  For instance, I have
classes Ship and Shot, can I use code like this:

Ship::Fire()
{
	Shot gun(x + 20, y + 8); //constructor takes x and y for shot
};

Ship::Update()
{
	if (Shot::pFirst)
	{
		Shot::pFirst->Update()
	};
};

Basically, I need to know if a variable constructed in a function can be
made to not be destructed at the end of that function, and have it
visible globally? If not, does anyone know how to make a linked list of
objects so I can have more than one object of any one type on screen at
one time?

thanks in advance,
-- 
-Begin Signature-
Isaac Waldron <waldroni AT lr DOT net> N1YZI
http://www.geocities.com/SiliconValley/Lakes/5703/home.html
-End Signature-

- Raw text -


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