p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C++ Programming (http://p2p.wrox.com/forumdisplay.php?f=89)
-   -   Help a student re: Re-using variables (http://p2p.wrox.com/showthread.php?t=38103)

random_eh February 6th, 2006 05:49 PM

Help a student re: Re-using variables
 
In main I use a variable say "char user_input;" then I no longer have a need for that particular variable. However, I do need another variable say "char function_result;"

The way I see it I can easily do two things:
 1) make a new variable
 2) or use the old variable
but is there a way to rename the old variable with the new name?

klep February 7th, 2006 12:54 AM

Nope. Make a new one -- it's stylistically more pleasing for a tiny (and temporary) impact on memory consumption.

----
Scott J. Kleper
Author, "Professional C++"
(Wrox, 2005)

mikhailberis February 7th, 2006 04:57 PM

There is a way, but it might be clumsy.

You can do something like this:

...
char my_first_char;
// do other things
// then use the old variable
// to use the space of the old variable
char & another_char(my_first_char);

Dean Michael C. Berris
Orange and Bronze Technologies, Inc.
Mobile +639287291459

vector February 27th, 2006 08:47 AM

Its not renaming...it's giving another name. :)



All times are GMT -4. The time now is 02:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.