Function Parameters

Is it better to have pointers to objects outside of the function, so that the other function can use them, or is it better to send addreses of those objects as parameters to the other function?
You should avoid global variables where possible.

If you design your software in an object oriented manner your software consists solely of a set of objects. Some of them may contain other objects or have references to others. Those are attributes of the object (I think C++ guys call them "members").
If an object sends a message to itself it doesn't need to parametrize it with its attributes, because its method implementations have full access to all of them.
If it sends a message to another object then it should parametrize it with references to objects the receiver may use to handle the addressed method.

If you don't use OOP then in general it is not the best idea to let functions access global objects. You may lose flexibility and control of your process flow.
I'm currently using pointers to Sprite objects so that my function can make some changes on them. But I think I wont need that function when I optimese the code to do everything on begining.
I'll try to avoid global variables in future...
so that my function can make some changes on them
Your functions should never change your objects state by modifying their attributes values directly. Instead they should ask the object to do so. The simplest way may be to send an object a message to set some attributes value. The setters implementation may check the given new value and possibly inhibit access or may in turn modify some other possibly derived attributes.

F.e.: A circle may have the attributes radius and area. Both depend on each other. Setting radius may in turn force recalculation of the area. Or the new radius value may be rejected because of an inappropriate value.
If you would directly access one of those attributes from elsewhere the receiver may never have the chance to hold its state consistent. (Sorry, my english isn't the best one).
I don't directly acces the variables, sfml dosen't allow that because of the reasons you mentioned.
Topic archived. No new replies allowed.