defining a global within a function

Started by
2 comments, last by hibiki_konzaki 21 years, 5 months ago
Is it possible to create a global object from within a function? Like if you have a class cat in a game, and the player goes and buys a cat, can you define a global cat from some function? Thanks. Hibiki Wheres the any key?
find your element at mutedfaith.com. <º>
HibikiWheres the any key?www.geocities.com/dragongames123/home.html
find your elementat mutedfaith.com.<º>
Advertisement
I am a newbie- but wouldn''t the cat have enough scope in the class you called it from (it ideally should)?

And if it doesn''t then you could simply make an accessor function( cat* getCat() from within the cat-calling class.

Or maybe singletons would help here?





__________________________

/]// ____s/s]ssx
//s;:_____//};;;/
][ ][][
[] [] [ss
i am super ascii artist 1337
(it is a crazy donkey)
quote:Original post by hibiki_konzaki
Is it possible to create a global object from within a function? Like if you have a class cat in a game, and the player goes and buys a cat, can you define a global cat from some function? Thanks.


If you ever find yourself in the situation where you think you have to do this, then you are not thinking properly. Either store the data to a global linked list or one in a singleton, or pass an object to the function and have the data stored within that object. A program should never ever have to make a global variable from within a function.
I see. Thanks.
HibikiWheres the any key?www.geocities.com/dragongames123/home.html
find your elementat mutedfaith.com.<º>

This topic is closed to new replies.

Advertisement