Jump to content
  • Advertisement


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


defining a global within a function

This topic is 5729 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
][ ][][
[] [] [ss
i am super ascii artist 1337
(it is a crazy donkey)

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!