Jump to content

  • Log In with Google      Sign In   
  • Create Account


C++ & SFML?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#21 wintertime   Members   -  Reputation: 1642

Like
0Likes
Like

Posted 16 October 2013 - 11:19 AM

That sounds like you want everything to access everything, when it would be safer to only have the higher level logic know about all those systems.



Sponsor:

#22 Dragonsoulj   Crossbones+   -  Reputation: 2086

Like
0Likes
Like

Posted 16 October 2013 - 08:31 PM

If you want to have a private variable that stores the window, change it to a pointer and create a window with new:

 

In declaration:

sf::RenderWindow * mWindow;

 

In constructor:

mWindow = new sf::RenderWindow(sf::VideoMode(640, 480), "SFML!");

 

In destructor:

delete mWindow;


#23 Satharis   Members   -  Reputation: 949

Like
0Likes
Like

Posted 17 October 2013 - 02:56 AM

It's not exactly a singleton. I just need my input object, sound object, gui object etc to access each other.

Which works fine if you pass references between things or have a container object to access them, if code was "just better" to have everything public and visible to each other we wouldn't have access modifiers at all.

I think passing things around all the time is more like spaghetti code than to have 1 single place to store a reference to something. Less typing as well.

I could argue against this but frankly there's at least a couple hundred live or half-dead threads on these forums going over this topic so I'm not going to bother, needless to say most people here are going to suggest you not just make everything global, public, or a singleton just because you think it makes it easier to type/deal with.

Hint: It doesn't. Definitely not in the long term.

#24 boogyman19946   Members   -  Reputation: 1051

Like
0Likes
Like

Posted 17 October 2013 - 01:56 PM

I was able to make it work.

 

It's not exactly a singleton. I just need my input object, sound object, gui object etc to access each other.

 

I think passing things around all the time is more like spaghetti code than to have 1 single place to store a reference to something. Less typing as well.

 

There is a lot of hidden dangers with using globally accessible variables. For one thing, it's hard to keep track of all the points of access. Because the objects can be accessed at any time, there is little options for the code to tell you that you need to initialize some global variable before the code can work correctly. At some point you'll forget that one of the classes in your code depends on a global variable and you'll forget to initialize it. Now you're wasting time fixing something that could have been prevented had you declared it as an input argument in your constructor. Sure, you can declare everything global, but you should keep in mind that scoping and proper class interfaces are there to tell you what information you need and hide information that should not be accessed elsewhere. It limits how many things you'll have to focus on and will keep you from creating functions that have hidden side effects.


"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS