Archived

This topic is now archived and is closed to further replies.

defining a global within a function

This topic is 5514 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites